Navigation refers to the interactions that let users navigate across, into, and back out from the different pieces of content within your app.
Android Jetpack's Navigation component helps you implement navigation, from simple button clicks to more complex patterns, such as app bars and the navigation drawer.
The Navigation component also ensures a consistent and predictable user experience by adhering to an established set of principles.
Navigation key parts
The Navigation component consists of three key parts, which are described below:
- Navigation graph: An XML resource that contains all navigation-related information in one centralized location. This includes all the individual content areas within your app, called destinations, as well as the possible paths that a user can take through your app.
NavHost: An empty container that displays destinations from your navigation graph. The Navigation component contains a default
NavHostFragment, that displays fragment destinations.
NavController: An object that manages app navigation within a
NavControllerorchestrates the swapping of destination content in the
NavHostas users move throughout your app.
As you navigate through your app, you tell the
NavController that you want to
navigate either along a specific path in your navigation graph or directly to a
specific destination. The
NavController then shows the appropriate destination
The Navigation 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.
- Implementing and handling deep linking.
- Including Navigation UI patterns, such as navigation drawers and bottom navigation, with minimal additional work.
- Including Safe Args, a Gradle plugin that provides type safety when navigating and passing data between destinations.
ViewModelsupport—you can scope a
ViewModelto a navigation graph to share UI-related data between the graph's destinations.
In addition, you can use Android Studio's Navigation Editor to view and edit your navigation graphs.
Navigation is compatible with the latest stable version of Android Studio.
For more documentation and resources related to the Navigation component, see the following resources.
- Principles of Navigation
- Design for different form factors
- Ensure compatibility with gesture navigation
- Design navigation graphs
- Nested navigation graphs
- Global actions
- Conditional navigation
- Pass data between destinations
- Create a deep link for a destination
- Animate transitions between destinations
- Update UI components with NavigationUI
- Create swipe views with tabs using ViewPager
- Interact programmatically with the Navigation component
- Test navigation
- Add support for new destination types
- Provide custom back navigation
- Migrate to the Navigation component
- Learn Jetpack Navigation
- Fragments and the Navigation Component
- Build an adaptive app with dynamic navigation
- Navigating Navigation
- 10 Best Practices for Moving to a Single Activity
- Single Activity: Why, When, and How (Android Dev Summit '18)
- Android Jetpack: Manage UI navigation with Navigation Controller (Google I/O '18)