I have a welcome screen containing two buttons:Login
and Sign Up
.
Hence I have a screen for each one: login screen
and sign up screen
.
Both of them are in the same NavGraphBuilder
. Users can navigate from sign up
screen to login
screen and vice versa.
At the moment, when the user is on the login screen and clicks on the signUp screen, the screen is added to backQueue
even though it already exists.
I try to prevent new destination recreation by applying singleTop
like this:
navController.navigate(AuthenticationNavGraph.SignInScreen.route) {
this.launchSingleTop = true
}
But no progress. So how can I prevent new screen recreation if the screen already exists on backQueue
?
Please try restoreState = true
:
navController.navigate(item.route) {
// Pop up to the start destination of the graph to
// avoid building up a large stack of destinations
// on the back stack as users select items
navController.graph.startDestinationRoute?.let { route ->
popUpTo(route) {
saveState = true
}
}
// Avoid multiple copies of the same destination when
// reselecting the same item
launchSingleTop = true
// Restore state when reselecting a previously selected item
restoreState = true
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With