https://kotlinlang.org logo
#compose
Title
# compose
a

amar_1995

08/20/2020, 6:45 PM
I am using `avedInstanceState`in 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()
z

Zach Klippenstein (he/him) [MOD]

08/20/2020, 6:47 PM
What type are you trying to save?
a

amar_1995

08/20/2020, 6:47 PM
Custom object
z

Zach Klippenstein (he/him) [MOD]

08/20/2020, 6:48 PM
That error message is pretty clear imo, what part doesn’t make sense?
a

amar_1995

08/20/2020, 6:49 PM
Do I need to add
saver
in custom object part ?
f

Foso

08/20/2020, 6:50 PM
dev14 or dev17?
a

amar_1995

08/20/2020, 6:50 PM
dev14
f

Foso

08/20/2020, 6:51 PM
try dev17
a

amar_1995

08/20/2020, 6:51 PM
okay
z

Zach Klippenstein (he/him) [MOD]

08/20/2020, 6:54 PM
You pass the saver to
rememberSavedInstanceState
a

amar_1995

08/20/2020, 7:35 PM
Copy code
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)``
z

Zach Klippenstein (he/him) [MOD]

08/20/2020, 7:46 PM
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”
a

amar_1995

08/20/2020, 8:00 PM
It is niether. It just a simple class
I am trying do the above same way
z

Zach Klippenstein (he/him) [MOD]

08/20/2020, 8:13 PM
Right, so you need to return something from the
save
lambda that can be stored in a
Bundle
.
a

amar_1995

08/20/2020, 8:18 PM
Is there any example for this ?
z

Zach Klippenstein (he/him) [MOD]

08/20/2020, 8:33 PM
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
.
👍 1
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
.
a

amar_1995

08/20/2020, 8:47 PM
Got your point thanks