lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey

Implement conditional navigation

Your app might have a series of conditional destinations which are destinations that are only used under certain conditions, such as when a user needs to log in. These destinations should be created as separate destinations, or a nested navigation graph, that another destination launches as needed. Figure 1 shows the user navigating to a profile destination that, having determined the user isn’t logged in, requires the user to navigate to a login destination. The Login destination then returns the user back to the Profile destination after login is complete.

Figure 1. Conditional navigation.

The Login destination should pop itself off the navigation stack after it returns to the Profile destination. Call the popBackStack() method when navigating back to the original destination. The original destination will “pop” off the navigation stack and become active.