My Home navigation target is dynamic, because it has a ViewPager
What is the right way to navigate to the top of the stack?
I ended up using a while loop and popBackStack, because it doesn't see to work if I don't know the route exactly. cc @Steve Bower [G]
Copy code
fun navigateToPlayer(clearBackstack: Boolean = true) {
val route = NavigationScreens.Player.route + "?page=0"
if (clearBackstack) {
while (navController.popBackStack()) {}
navController.navigate(route)
} else {
navController.navigate(route)
}
}
s
Steve Bower [G]
02/04/2022, 4:16 PM
Have you looked at popUpTo and popUpToInclusive (which can be passed as part of the navigate() call)? See
https://www.youtube.com/watch?v=mLfWvSGG5c8▾
y
yschimke
02/04/2022, 5:08 PM
I tried that, it didn't work which I put down the the variable part of the route (the query params...). But I'll try again and maybe strip all params from the popupTo?
yschimke
02/04/2022, 5:17 PM
It kind of makes sense. If I have route epidode?id=1234 and then try to pop up epidode?id=1235 or epidode I wouldn't expect it to be correct, although it doesn't seem to pop up at all if names mismatch, while docs say all non matching get removed.
yschimke
02/04/2022, 5:18 PM
I'll make a clean repro and file a bug for it silently not removing them.