Thread
#compose
    amar_1995

    amar_1995

    2 years ago
    I am using avedInstanceStatein dev14 but getting this error
    cannot be saved using the current UiSavedInstanceStateRegistry. The default implementation only supports types which can be stored inside the Bundle. Please consider implementing a custom Saver for this class and pass it to savedInstanceState() or rememberSavedInstanceState()
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    What type are you trying to save?
    amar_1995

    amar_1995

    2 years ago
    Custom object
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    That error message is pretty clear imo, what part doesn’t make sense?
    amar_1995

    amar_1995

    2 years ago
    Do I need to add
    saver
    in custom object part ?
    Foso

    Foso

    2 years ago
    dev14 or dev17?
    amar_1995

    amar_1995

    2 years ago
    dev14
    Foso

    Foso

    2 years ago
    try dev17
    amar_1995

    amar_1995

    2 years ago
    okay
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    You pass the saver to
    rememberSavedInstanceState
    amar_1995

    amar_1995

    2 years ago
    val navigationSaver = Saver<NavigationStack<MainScreen>, NavigationStack<MainScreen>>(
        save = { it },
        restore = {  NavigationStack(init = MainScreen.Watchlist) }
    )
    
    this.navigation = rememberSavedInstanceState<NavigationStack<MainScreen>>(saver = navigationSaver) {
        NavigationStack(init = MainScreen.Watchlist)
    }
    Above code is giving me
    java.lang.IllegalStateException: Check  failed.
    error
    Check failed.
    at androidx.ui.savedinstancestate.ValueProvider$updateAndReturnValue$1.invoke(RememberSavedInstanceState.kt:106)
    at androidx.ui.savedinstancestate.UiSavedStateRegistryImpl.performSave(UiSavedStateRegistry.kt:116)
    at androidx.ui.core.SavedStateDelegate.dispatchSaveInstanceState(SavedStateDelegate.kt:106)
    `at androidx.ui.core.AndroidComposeView.dispatchSaveInstanceState(AndroidComposeView.kt:690)``
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    Is
    NavigationStack
    Serializable
    or
    Parcelable
    ? The error message you posted initially says “The default implementation only supports types which can be stored inside the Bundle”
    amar_1995

    amar_1995

    2 years ago
    It is niether. It just a simple class
    I am trying do the above same way
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    Right, so you need to return something from the
    save
    lambda that can be stored in a
    Bundle
    .
    amar_1995

    amar_1995

    2 years ago
    Is there any example for this ?
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    The example you posted does it. It returns/restores
    Holder.value
    , which is an
    Int
    , i.e. something that can be stored in a
    Bundle
    .
    The saver is basically your serialization/deserialization logic, but instead of serializing to a byte array, you’re serializing to any of the types supported by
    Bundle
    .
    amar_1995

    amar_1995

    2 years ago
    Got your point thanks