My app has 2 screens:
ScreenA -> Has text that says "Screen A" and button. When button is pressed it leads to ScreenB
ScreenB -> Has text that says "Screen B" At the bottom of every screen there is Navigation bar with two icons that lead to ScreenA and ScreenB
Link to entire code: https://pastecode.io/s/ndzeeu6r
Issue:
When navigating trough button to ScreenB, if I navigate with navController.navigate(B.route)
When navigating trough NavigationBarItem If I navigate with extension function navController.navigateSingleToTop(newRoute)
fun NavController.navigateSingleToTop(route: String){
this.navigate(route){
launchSingleTop=true;
popUpTo([email protected]){
saveState= true
}
restoreState= true
}
}
When navigation is implemented like this, following scenario occurs:
- App opens on ScreenA
- I press button on ScreenA
- ScreenB opens
- I press NavigationBarItem that's linked to ScreenA
- I stay on ScreenB
My question is why doesn't the navigation to ScreenA work? What's being pushed and popped of the backstack? There is some issue with flags saveState and restoreState, when they are not set it works fine. Why?
Thanks
I tried reading documentation to get better understanding, but I wasn't able to understand why does this happen. I know that it works okay when I remove saveState flag or If I use navigateSingleToTop on both places. But I still don't understand why this code doesn't work right