Handling fragment transactions.<\/p>
Handling Up and Back actions correctly by default.<\/p>
Providing standardized resources for animations and transitions.<\/p>
Implementing and handling deep linking.<\/p>
Including Navigation UI patterns, such as navigation drawers and bottom navigation, with minimal additional work.<\/p>
Safe Args – a Gradle plugin that provides type safety when navigating and passing data between destinations.<\/p>
ViewModel<\/code> support – you can scope a ViewModel<\/code> to a navigation graph to share UI-related data between the graph’s destinations.<\/p><\/blockquote>\n\n\n\nWhat is the Navigation Architecture Component?<\/h3>\n\n\n\n
The Navigation Architecture Component comprises of a number of different sub components which are used to handle navigation within an Android app, these include the following.<\/p>\n\n\n\n
- The Navigation Graph<\/li>
- The NavHostFragment<\/li>
- The NavController<\/li><\/ul>\n\n\n\n
The Navigation Graph is a new resource type used to centralise information relating to navigation within your Android app including Destinations and Actions. Destinations are views that you can navigate to within your app such as Fragments or Activities. Actions represent the transitions a user can make between Destinations inside your app. The Navigation Graph is an XML file that can be modified manually but it can also be changed using the Navigation Editor available in Android Studio 3.3 and above.<\/p>\n\n\n\n
The Navigation Editor shows a visual representation of your Navigation Graph in a directed graph. The nodes displayed in the Navigation Editor are the Destinations and the nodes are connected with the Actions. The Navigation Editor allows you to view and modify the Desintations and Actions to you will have in your app. The changes when made in the editor will be reflected in the Navigation Graph resource XML file allowing you to keep to track of changes in version control.<\/p>\n\n\n\n
The NavHostFragment is placed inside the layout of your Activity and acts as a window allowing you to show the correct Fragment Destination within your Navigation Graph and swap it out with other Fragment Destinations as the user navigates through your app.<\/p>\n\n\n\n
The NavController is used to navigate to a particular Destination within your Navigation Graph by referencing either a Destination or Action. The SafeArgs plugin can be used to support type safe navigation and argument passing when using the NavController.<\/p>\n\n\n\n
Using Navigation Architecture Component in Java<\/strong><\/h2>\n\n\n\nStep 1: Adding the Navigation Component Dependencies<\/h3>\n\n\n\n
In order to use the navigation component in your Android project you will need to include the latest navigation-ui and navigation-fragment dependencies in your app’s build.grade file.<\/p>\n\n\n\n
See the following excerpt from a build.gradle file in the app directory which includes the latest navigation architecture component dependencies.<\/p>\n\n\n