Robert Menke
03/06/2022, 4:33 AMpopUpTo
correctly. I have a registration flow where I (for illustrative purposes) navigate to A
-> B
-> C
-> D
-> SignedIn
.
When I navigate to my SignedIn
route like so
navController.navigate("SignedIn") {
popUpTo("D") { inclusive = true }
}
and then press back the app goes back to C
. When I continue to press back it goes to B
and then A
. It seems like my call to popUpTo
is ONLY taking D
off the back stack rather than popping all previous destinations from the back stack. What am I misunderstanding?Tash
03/06/2022, 4:42 AMinclusive = true
?navController.navigate("SignedIn") {
popUpTo("A") { inclusive = true }
}
Robert Menke
03/06/2022, 4:49 AMD
. When I specify inclusive = false, back navigates back to D
which is what I’d expect.Tash
03/06/2022, 9:54 AMpopUpTo("A") { inclusive = true }
?
See this example for using popUpTo
for bottom nav bar, esp this snippet:
// 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
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
popUpTo
usageRobert Menke
03/06/2022, 5:15 PM// Pop everything up to and including the "home" destination off
// the back stack before navigating to the "friendslist" destination
navController.navigate("friendslist") {
popUpTo("home") { inclusive = true }
}
The example from the same page indicates it will pop everything up to and including home
Tash
03/07/2022, 1:28 AMpopUpTo
in terms of a stack (LIFO). If you have already navigated A
-> B
-> C
-> D
and you want to clear that, you have to think in terms of popping the current stack one by one till you reach the desired node, so first you'd pop D
, then C
, then B
and finally A
. If you do popUpTo("D") { inclusive = true }
then it's just going to pop up to (and including) D
.Robert Menke
03/07/2022, 1:33 AM