Andrew Leung
02/11/2022, 5:32 PMjava.lang.IllegalStateException: You cannot access the NavBackStackEntry's ViewModels after the NavBackStackEntry is destroyed.
at androidx.navigation.NavBackStackEntry.getViewModelStore(NavBackStackEntry.kt:207)
at com.google.accompanist.navigation.animation.AnimatedNavHostKt.AnimatedNavHost(AnimatedNavHost.kt:144)
at com.google.accompanist.navigation.animation.AnimatedNavHostKt$AnimatedNavHost$11.invoke(Unknown Source:23)
at com.google.accompanist.navigation.animation.AnimatedNavHostKt$AnimatedNavHost$11.invoke(Unknown Source:10)
at androidx.compose.runtime.RecomposeScopeImpl.compose(RecomposeScopeImpl.kt:140)
at androidx.compose.runtime.ComposerImpl.recomposeToGroupEnd(Composer.kt:2158)
at androidx.compose.runtime.ComposerImpl.skipCurrentGroup(Composer.kt:2404)
at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:2585)
at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:2571)
at androidx.compose.runtime.SnapshotStateKt__DerivedStateKt.observeDerivedStateRecalculations(DerivedState.kt:247)
at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(Unknown Source:1)
at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:2571)
at androidx.compose.runtime.ComposerImpl.recompose$runtime_release(Composer.kt:2547)
at androidx.compose.runtime.CompositionImpl.recompose(Composition.kt:620)
at androidx.compose.runtime.Recomposer.performRecompose(Recomposer.kt:786)
at androidx.compose.runtime.Recomposer.access$performRecompose(Recomposer.kt:105)
This is on latest 2.5.0-alpha01, but was also occurring on 2.4.0-alpha01 (but with a different error message)popWithTransition
but not entirely sure if that’s the cause), then the destination being popped’s navhost seemingly tries to recompose, which leads it to run L:144 in the AnimatedNavHost code`
navController.setViewModelStore(viewModelStoreOwner.viewModelStore)
which when retrieving the viewModelStore from it’s backStackEntry, it has already moved to the DESTROYED
state, thus leading to the IllegalStateExceptionIan Lake
02/11/2022, 6:13 PMEric Chee
02/15/2022, 10:22 PMIan Lake
02/15/2022, 10:41 PMEric Chee
02/15/2022, 10:44 PMscana
12/19/2022, 1:42 PMAndrew Leung
12/19/2022, 2:59 PM