How to save and restore navigation state in Jetpack Compose?

Viewed 544

I want to navigate to another screen, but i want to save current state, and then restore it. I tried to do as described in the bottom navigation documentation:

navController.navigate(Screen.CameraScreen.route) {
        popUpTo(navController.graph.id) {
            saveState = true
        }
    restoreState = true
}

But it doesn't work.

1 Answers

Try this:

navController.navigate(Screen.CameraScreen.route) {
        navController.graph.startDestinationRoute?.let { route ->
            popUpTo(route) {
                saveState = true
            }
        }
        launchSingleTop = true
        restoreState = true
    }
Related