Navigation Component

Navigation Component is responsible for defining what UI content the user will see in window. In practice, it defines which fragment will be shown to the user while he/she navigates through app, since Navigation Component is designed for apps that have one main activity with multiple fragment destinations.


Navigation component's parts

The Navigation component is composed by:
  • Destinations are the different content areas in your app. In practice, it is your fragments.
  • Actions are logical connections between your destinations that represent paths that users can take.
  • Navigation graph is a resource file that contains all of your destinations and actions. The graph represents all of your app's navigation paths.
  • NavHost is empty container that displays destinations from your navigation graph. The Navigation component contains a default NavHost implementation, NavHostFragment, that displays fragment destinations.
  • NavController orchestrates the swapping of destination content in the NavHost as users move throughout your app.
The figure below shows a visual representation of a navigation graph for a sample app containing six destinations connected by five actions. Each destination is represented by a preview thumbnail, and connecting actions are represented by arrows that show how users can navigate from one destination to another.


How to implement?

1. Include dependencies.
2. Create navigation graph (you must need the fragments already created before). 
3. Add NavHost to the Activity's layout.
4. Setup NavController to orchestrates the swapping of fragments in the NavHost on Activity's onCreate() lifecycle callback.