Add support for new destination types
Stay organized with collections Save and categorize content based on your preferences.

The NavController type relies on one or more Navigator objects to perform the navigation operation. By default, NavController supports leaving the navigation graph by navigating to another activity using the ActivityNavigator class and its nested ActivityNavigator.Destination class.

To navigate to any other type of destination, one or more additional Navigator objects must be added to the NavController. For example, when using fragments as destinations, the NavHostFragment automatically adds the FragmentNavigator class to its NavController.

To add a new Navigator object to a NavController, use the getNavigatorProvider() method, followed by the addNavigator() method.

The following code shows an example of adding a CustomNavigator object to a NavController:

Kotlin

valcustomNavigator=CustomNavigator()
navController.navigatorProvider+=customNavigator

Java

CustomNavigatorcustomNavigator=newCustomNavigator();
navController.getNavigatorProvider().addNavigator(customNavigator);

Most Navigator classes have a nested destination subclass. This subclass can be used to specify additional attributes unique to your destination. For more information about destination subclasses, see the reference documentation for the appropriate Navigator class.

Additional resources

To learn more about navigation, see the following additional resources.

Codelabs

Videos

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2025年02月10日 UTC.