Navigation is a crucial part of app design. With navigation, you design the interactions that allow users to move across, into, and back out from the different content areas within your app.
Navigation Architecture Component
The Navigation Architecture Component helps you implement common, but complex navigation requirements in your app, enabling you to more easily provide consistent and predictable experiences for your users.
Navigation handles navigating between your app's destinations--that is,
anywhere in your app to which users can navigate. While destinations are usually
Fragments representing specific screens, the Navigation Architecture Component
supports the other destination types listed below:
- Navigation graphs and subgraphs - when the destination is a graph or subgraph, users navigate to the start destination of that graph or subgraph
- Custom destination types
These destinations are connected via actions, and a set of destinations and connecting actions comprise an app's navigation graph.
The Navigation Architecture Component provides a number of other benefits, including the following:
- Handling Fragment transactions
- Handling Up and Back actions correctly by default
- Providing standardized resources for animations and transitions
- Treating deep linking as a first-class operation
- Including Navigation UI patterns, such as navigation drawers and bottom navigation, with minimal additional work
- Providing type safety when passing information while navigating
- Visualizing and editing navigation graphs with Android Studio's Navigation Editor
Principles of navigation
The Navigation Architecture Component is based on the following design principles:
Fixed start destination
Apps should have a fixed start destination, which is the screen the user sees when they launch your app from the launcher and also the last screen the user sees before return to the launcher when pressing the back button.
Navigation state should be represented via a stack of destinations
A navigation stack should have the start destination of the app at the bottom of the stack and the current destination at the top of the stack.
Operations that change the navigation stack should always operate on the top of the navigation stack, either by pushing a new destination onto the top of the stack or popping the top-most destination off the stack.
The Up button never exits your app
If a user is at the start destination the Up button should not be shown. When your app is launched using a deep link on another app's task, Up should take users to the hierarchical parent destination and not back to the other app.
Up and Back are identical within your app's task
When the system Back button would not exit your app, such as when you are on your own task and not on the start destination, the Up button should function identically to the system Back button.
Deep linking and navigating to a destination should yield the same stack
A user should be able to use the Back or Up button, regardless of how they got to a destination, to navigate through destinations back to the start destination.
When deep linking, any existing navigation stack is removed and replaced with the deep link’s navigation stack.
- Update UI components with NavigationUI
- Nested Navigation graphs
- Pass data between destinations
- Global actions
- Conditional destinations
- Custom destination types
- Android Jetpack: manage UI navigation with Navigation Controller (Google I/O 2018)
- Migrate an existing project to the Navigation Architecture Component