Marcin Wisniowski
03/27/2023, 8:48 PMpopUpTo
with include = true
to result in the behavior I want, but it does not.popUpTo(0)
, which doesn't seem documented anywhere.Stylianos Gakis
03/27/2023, 10:29 PMPop up to a given destination before navigating. This pops all non-matching destinations from the back stack until this destination is found.
So I guess it will try to pop everything since none of your destinations will have an ID of 0?
But with that said, I don’t think what you explain is how navigation works with this library, it always expects you to have a fixed startDestination, so going back should always lead to there before it leads to exiting the app.
When you say “would expect going to another screen to clear the backstack so the new screen is at the root of the backstack” do you mean that you’d expect this to happen by default?
Might be interesting to give this https://developer.android.com/guide/navigation/navigation-principles#fixed_start_destination a read to see what I mean by thatMarcin Wisniowski
03/28/2023, 12:53 AMWhen you say “would expect going to another screen to clear the backstack so the new screen is at the root of the backstack” do you mean that you’d expect this to happen by default?Not by default, but when I use popUpTo(startDestination) with
inclusive = true
.
it always expects you to have a fixed startDestination, so going back should always lead to there before it leads to exiting the app.That's a fair default, but if the app contains 3 screens switchable with a bottom navbar, then none of the screens is more "root" than the other. Screen A is the start destination, but pressing back at screen B shouldn't switch you to screen A. Switching screens with a bottom navbar should not populate the backstack.
Ian Lake
03/28/2023, 3:11 AMStylianos Gakis
03/28/2023, 9:35 AMval startDestination = navController.graph.startDestination
navController.navigate(startDestination, navOptions { popUpTo(startDestination) {inclusive = true } })
is only suggested if “this would be appropriate if your start destination does not require login”. Meaning that if it does not you need to exit the app.
And since you’re doing all this from the top of the backstack you don’t get the predictive back gesture animation either which would help the users understand that they are exiting the app. Not to mention in Android 14 they’d actually get the predictive back gesture which shows they’ll stay in the app, then that screen comes up, navController.currentBackStackEntry!!.savedStateHandle
and from it savedStateHandle.getLiveData<Boolean>(LOGIN_SUCCESSFUL)
is fetched and it is false
, and then you exit the app, completely changing the expectations the users have when seeing that animation as they don’t stay in the app.Marcin Wisniowski
03/28/2023, 9:04 PMNope. The screen you start the user on should be the screen they exit the app from. This has been confirmed through multiple UX studies we've ranAll right then, that is useful information! I feel like this could be mentioned here that it's intentional, it just felt like a bug to me.
Ian Lake
03/28/2023, 9:41 PMMarcin Wisniowski
03/28/2023, 10:46 PMIan Lake
03/28/2023, 11:04 PMMarcin Wisniowski
03/29/2023, 9:42 AM