My project has a bottom bar with tabs A, B and C. Tab C view has its own navigation C1, C2, C3. Now if the user navigates e.g. C -> C1 -> C2, than goes to tab B, than back to tab C again, I want him to immediately land on tab C2 (from which he left C tab). And here the multiple back stacks technique provided by Android documentation works well:
navController.navigate(selectedBottomNavRoute) {
launchSingleTop = true
restoreState = true
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
}
The key is saveState = true
which "saves" and recreates the state of the child navigation controller used for C1-C2-C3 navigation.
But the problem is that when I use popUpTo
I lose the back stake of navController. And without popUpTo
I can't use saveState
functionality.
Using this technique, if the user simply navigates A -> B -> C, presses the "Back" button, he appears in A! But obviously he expects to appear in B.
Is it possible to implement multiple back stacks without losing the back stack of the "parent" navigation controller?
After all, why did Android devs implement the saveState
function inside PopUpToBuilder and not, for example, in NavOptionsBuilder? :)