<https://stackoverflow.com/questions/79104688/chan...
# compose-android
r
https://stackoverflow.com/questions/79104688/changing-back-stack-with-multiple-back-stack-bottomnavigation-with-type-safety-i . Is it possible to build you own stack for navigation and control them by re-ordering using compose navigation.
r
each tab will have its own nested graph. But lets say you had 3 tabs. you switch between tabs and click back you would end up in start destination right?
s
Can you define a bit more clearly where you would be at that given moment before you press back? From the three tabs, which one are you in? And for those 3 tabs, what is the saved backstack looking like for them?
r
ok. Lets say i have A B C as bottom tabs. I switch from A to B to C to B. Now when you click back it would navigate to A which is the start destination. What if i wanted the back stack like on back press like B to C to A having just one instance of these in stack.
s
If you do not want C to leave your backstack as you navigate back to B, then you need to not call
popUpTo(navController.graph.findStartDestination().id)
, since that is the line which pops C out of your backstack in that last step where you go back to B.
r
got it!. Thanks. so we don't need a custom stack. I over complicated my thinking here!
But with this won't we create a huge stack if user switches multiple times
s
If you keep
singleTop = true
my understanding is that it won't put the graphs on top of each other indefinitely, since there can only be one instance of them in the backstack.
With all that said btw, I will just give my personal opinion about this. Changing the back button to do what you are saying here is a bit of unexpected behavior, since you then make the back button unreliable, meaning if you are in B, sometimes back takes you to C, sometimes to A. It depends on where you were before, but that as a user may feel just like unreliable behavior. This is especially try if you for example had the app backgrounded and you just came back to it and you are on B. There's no way you remember if you came from A or C when you were last using the app, so it feels like the app is just doing random things on pressing back. I would personally advise against it.
r
Agree!. this is what we do (recommended approach) in our app. Just wanted to try something based on the SO question
👍 1