I am getting `java.lang.IllegalStateException: Al...
# compose
s
I am getting
java.lang.IllegalStateException: Already attached to lifecycleOwner
Crash when navigating back i am using navigation-compose:2.5.0-alpha02, is it a known issue?
java.lang.IllegalStateException: Already attached to lifecycleOwner
at androidx.lifecycle.SavedStateHandleController.attachToLifecycle(SavedStateHandleController.java:38)
at androidx.lifecycle.SavedStateHandleAttacher.onRecreated(SavedStateHandleSupport.kt:139)
at androidx.savedstate.Recreator.reflectiveNew(Recreator.java:90)
at androidx.savedstate.Recreator.onStateChanged(Recreator.java:62)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:360)
at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:271)
at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:313)
at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:151)
at androidx.lifecycle.LifecycleRegistry.setCurrentState(LifecycleRegistry.java:121)
at androidx.navigation.NavBackStackEntry.updateState(NavBackStackEntry.kt:188)
at androidx.navigation.NavBackStackEntry.setMaxLifecycle(NavBackStackEntry.kt:156)
at androidx.navigation.NavController.updateBackStackLifecycle$navigation_runtime_release(NavController.kt:987)
at androidx.navigation.NavController.dispatchOnDestinationChanged(NavController.kt:892)
at androidx.navigation.NavController.onGraphCreated(NavController.kt:1161)
at androidx.navigation.NavController.setGraph(NavController.kt:1086)
at androidx.navigation.NavController.setGraph(NavController.kt:100)
at androidx.navigation.compose.NavHostKt.NavHost(NavHost.kt:120)
at androidx.navigation.compose.NavHostKt.NavHost(NavHost.kt:69)
I can reproduced this crash with this Code
Copy code
val nav = rememberNavController()
NavHost(navController = nav,startDestination = "home") {
    composable("home") {
        val nested =  rememberNavController()
        NavHost(navController = nested,startDestination = "home1") {
            composable("home1") {
                Box(modifier = Modifier.fillMaxSize().background(Color.Red)) {
                    Button(onClick = {
                        nested.navigate("home2")
                    }) {

                    }
                }
            }
            composable("home2") {
                Box(modifier = Modifier.fillMaxSize().background(Color.Green)) {
                    Button(onClick = {
                        nav.navigate("home_detail")
                    }) {

                    }
                }
            }

        }
    }
    composable("home_detail") {
        Box(modifier = Modifier
            .fillMaxSize()
            .background(Color.Yellow)) {
            Button(onClick = {
                nav.popBackStack()
            }) {

            }
        }
    }
}
i
Yes, it is a problem in the latest Lifecycle library. You can try out a snapshot build following the directions at http://androidx.dev to confirm it is fixed before this next Wednesday's release