Zoltan Demant
02/25/2022, 10:09 AMZoltan Demant
02/25/2022, 10:10 AMval registry = LocalSaveableStateRegistry.current
val key = "boop"
val bundle = registry?.consumeRestored(key) as? Bundle
//TODO: bundle is used in my applications navigation
DisposableEffect(Unit) {
val entry = registry?.registerProvider(key) {
Bundle() // Filled with precious data
}
onDispose {
entry?.unregister()
}
}
Zoltan Demant
02/25/2022, 10:11 AMonDispose
is called before the app has managed to save its state (under certain circumstances)?
https://issuetracker.google.com/issues/221190158Zoltan Demant
02/25/2022, 10:11 AMAlbert Chang
02/25/2022, 2:35 PMSaveableStateRegistry.consumeRestored()
is a function with side effect so you shouldn't use it directly in a composable function. You should use val bundle = remember(registry) { registry?.consumeRestored(key) as? Bundle }
.Albert Chang
02/25/2022, 2:36 PMbundle
will become null.Zoltan Demant
02/25/2022, 2:59 PMrememberCoroutineScope()
which I dont think will change either?Zoltan Demant
02/25/2022, 3:38 PM