Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

androidx.navigation

Navigation is a framework for navigating between 'destinations' within an Android application that provides a consistent API whether destinations are implemented as Fragments, Activities, or other components.

There are 3 major components in Navigation.

Below is an example of working with a NavController.
 // File: HomeFragment.java
 public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
   // For example purposes, assume our layout created in onCreateView has a Button
   // that should navigate the user to a destination
   Button b = view.findViewById(R.id.view_details);

   b.setOnClickListener(v -> {
       // Retrieve the NavController from any View within a NavHost
       NavController navController = Navigation.findNavController(v);
       navController.navigate(R.id.details));
   }

   // Or use the convenience method in Navigation to combine the previous steps
   b.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.details));
 }
 

Please see the documentation of individual classes for details.

Annotations

NavDestination.ClassType This optional annotation allows tooling to offer auto-complete for the android:name attribute. 
Navigator.Name This annotation should be added to each Navigator subclass to denote the default name used to register the Navigator with a NavigatorProvider

Interfaces

FloatingWindow A marker interface for NavDestination subclasses that float above the view of other destinations (i.e. 
NavArgs An interface marking generated Args classes. 
NavController.OnDestinationChangedListener OnDestinationChangedListener receives a callback when the NavController.getCurrentDestination() or its arguments change. 
NavDirections An interface that describes a navigation operation: action's id and arguments  
NavHost A host is a single context or container for navigation via a NavController
Navigator.Extras Interface indicating that this class should be passed to its respective Navigator to enable Navigator specific behavior. 

Classes

ActionOnlyNavDirections An implementation of NavDirections without any arguments. 
ActivityNavigator ActivityNavigator implements cross-activity navigation. 
ActivityNavigator.Destination NavDestination for activity navigation  
ActivityNavigator.Extras Extras that can be passed to ActivityNavigator to customize what ActivityOptionsCompat and flags are passed through to the call to ContextCompat.startActivity(Context, Intent, Bundle)
ActivityNavigator.Extras.Builder Builder for constructing new ActivityNavigator.Extras instances. 
NavAction Navigation actions provide a level of indirection between your navigation code and the underlying destinations. 
NavArgument NavArgument denotes an argument that is supported by a NavDestination
NavArgument.Builder A builder for constructing NavArgument instances. 
NavBackStackEntry Representation of an entry in the back stack of a NavController
NavController NavController manages app navigation within a NavHost
NavDeepLinkBuilder Class used to construct deep links to a particular destination in a NavGraph
NavDestination NavDestination represents one node within an overall navigation graph. 
NavGraph NavGraph is a collection of NavDestination nodes fetchable by ID. 
NavGraphNavigator A Navigator built specifically for NavGraph elements. 
NavHostController Subclass of NavController that offers additional APIs for use by a NavHost to connect the NavController to external dependencies. 
Navigation Entry point for navigation operations. 
Navigator<D extends NavDestination> Navigator defines a mechanism for navigating within an app. 
NavigatorProvider A NavigationProvider stores a set of Navigators that are valid ways to navigate to a destination. 
NavInflater Class which translates a navigation XML file into a NavGraph  
NavOptions NavOptions stores special options for navigate actions  
NavOptions.Builder Builder for constructing new instances of NavOptions. 
NavType<T> NavType denotes the type that can be used in a NavArgument
NavType.EnumType<D extends Enum> EnumType is used for NavArguments holding enum values. 
NavType.ParcelableArrayType<D extends Parcelable> ParcelableArrayType is used for NavArguments which hold arrays of Parcelables. 
NavType.ParcelableType<D> ParcelableType is used for passing Parcelables in NavArguments. 
NavType.SerializableArrayType<D extends Serializable> SerializableArrayType is used for NavArguments that hold arrays of Serializables. 
NavType.SerializableType<D extends Serializable> SerializableType is used for Serializable NavArguments.