package

androidx.navigation

Overview

Navigation is a framework for navigating between 'destinations' within an Android application that provides a consistent API whether destinations are implemented as Fragments, , 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.

Interfaces

FloatingWindowA marker interface for NavDestination subclasses that float above the view of other destinations (i.e.
NavArgsAn interface marking generated Args classes.
NavController.OnDestinationChangedListenerOnDestinationChangedListener receives a callback when the NavController.getCurrentDestination() or its arguments change.
NavDirectionsAn interface that describes a navigation operation: action's id and arguments
NavHostA host is a single context or container for navigation via a NavController.
Navigator.ExtrasInterface indicating that this class should be passed to its respective Navigator to enable Navigator specific behavior.

Classes

ActionOnlyNavDirectionsAn implementation of NavDirections without any arguments.
ActivityNavigatorActivityNavigator implements cross-activity navigation.
ActivityNavigator.DestinationNavDestination for activity navigation
ActivityNavigator.ExtrasExtras 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.BuilderBuilder for constructing new ActivityNavigator.Extras instances.
NavActionNavigation actions provide a level of indirection between your navigation code and the underlying destinations.
NavArgumentNavArgument denotes an argument that is supported by a NavDestination.
NavArgument.BuilderA builder for constructing NavArgument instances.
NavBackStackEntryRepresentation of an entry in the back stack of a NavController.
NavControllerNavController manages app navigation within a NavHost.
NavDeepLinkNavDeepLink encapsulates the parsing and matching of a navigation deep link.
NavDeepLink.BuilderA builder for constructing NavDeepLink instances.
NavDeepLinkBuilderClass used to construct deep links to a particular destination in a NavGraph.
NavDeepLinkRequestA request for a deep link in a NavDestination.
NavDeepLinkRequest.BuilderA builder for constructing NavDeepLinkRequest instances.
NavDestinationNavDestination represents one node within an overall navigation graph.
NavGraphNavGraph is a collection of NavDestination nodes fetchable by ID.
NavGraphNavigatorA Navigator built specifically for NavGraph elements.
NavHostControllerSubclass of NavController that offers additional APIs for use by a NavHost to connect the NavController to external dependencies.
NavigationEntry point for navigation operations.
Navigator<D>Navigator defines a mechanism for navigating within an app.
NavigatorProviderA NavigationProvider stores a set of Navigators that are valid ways to navigate to a destination.
NavInflaterClass which translates a navigation XML file into a NavGraph
NavOptionsNavOptions stores special options for navigate actions
NavOptions.BuilderBuilder for constructing new instances of NavOptions.
NavType<T>NavType denotes the type that can be used in a NavArgument.
NavType.EnumType<D>EnumType is used for NavArguments holding enum values.
NavType.ParcelableArrayType<D>ParcelableArrayType is used for NavArguments which hold arrays of Parcelables.
NavType.ParcelableType<D>ParcelableType is used for passing Parcelables in NavArguments.
NavType.SerializableArrayType<D>SerializableArrayType is used for NavArguments that hold arrays of Serializables.
NavType.SerializableType<D>SerializableType is used for Serializable NavArguments.
NoOpNavigatorA Navigator that only supports creating destinations.

Annotation Types

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