Chuck Stein
07/15/2021, 3:36 AMChuck Stein
07/15/2021, 3:44 AMallan.conda
07/15/2021, 4:33 AMIan Lake
07/15/2021, 5:23 AMChuck Stein
07/15/2021, 2:53 PMChuck Stein
07/15/2021, 10:44 PMmain_fragment
equivalent which can be a start destination that does not require auth. There is a login screen and a welcome screen, but the welcome screen requires auth. So it seems like to follow the principles of navigation, the welcome screen should be the start destination. Following the Conditional Navigation example, if the welcome screen opens and we have no auth, we redirect to the login screen. But if the user then presses the system back button on the login screen without logging in, we will return to the welcome screen which sees that login was unsuccessful via the saved state handle. From that point, in the example, we navigate to the unauthenticated start destination, main_fragment
. But in my app there is no unauthenticated start destination we can navigate to. We are already at the start destination (welcome screen), which requires auth. Ideally we should just exit the app at this point (if the user presses back from the login screen), but I see no way to do this via the nav controller. Calling popBackStack
from the welcome screen, even if we explicitly pop up to the start destination or the nav graph itself (inclusive), does not exit the app but just appears to display the nav graph on its own with no destination inside of it. I could instead invoke a callback to the activity's onBackPressed
or finish
method, but is this really the ideal way? This seems like a common use case and I feel like I should be able to handle it properly from within the Navigation Component.Ian Lake
07/16/2021, 12:11 AMfinish()
on the activity if you want to close the activity; NavController will never finish your activity for you; it's back stack and state is completely contained within the activityChuck Stein
07/16/2021, 12:41 AMBackHandler
to the composition on the login screen, which invokes a callback to the activity's finish
method. It seems that using the saved state handle is not necessary for my use case. I appreciate the help.