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
val customNavigator = CustomNavigator()
navController.navigatorProvider += customNavigator
Java
CustomNavigator customNavigator = new CustomNavigator();
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# Add support for new destination types\n\nThe [`NavController`](/reference/androidx/navigation/NavController) type\nrelies on one or more\n[`Navigator`](/reference/androidx/navigation/Navigator) objects to perform\nthe navigation operation. By default, `NavController` supports leaving the\nnavigation graph by navigating to another activity using the\n[`ActivityNavigator`](/reference/androidx/navigation/ActivityNavigator)\nclass and its nested\n[`ActivityNavigator.Destination`](/reference/androidx/navigation/ActivityNavigator.Destination)\nclass.\n\nTo navigate to any other type of destination, one or more additional `Navigator`\nobjects must be added to the `NavController`. For example, when using fragments\nas destinations, the\n[`NavHostFragment`](/reference/androidx/navigation/fragment/NavHostFragment)\nautomatically adds the\n[`FragmentNavigator`](/reference/androidx/navigation/fragment/FragmentNavigator)\nclass to its `NavController`.\n\nTo add a new `Navigator` object to a `NavController`, use the\n[`getNavigatorProvider()`](/reference/androidx/navigation/NavController#getNavigatorProvider())\nmethod, followed by the\n[`addNavigator()`](/reference/androidx/navigation/NavigatorProvider#addNavigator(androidx.navigation.Navigator))\nmethod.\n\nThe following code shows an example of adding a `CustomNavigator` object to a\n`NavController`: \n\n### Kotlin\n\n```kotlin\nval customNavigator = CustomNavigator()\nnavController.navigatorProvider += customNavigator\n```\n\n### Java\n\n```java\nCustomNavigator customNavigator = new CustomNavigator();\nnavController.getNavigatorProvider().addNavigator(customNavigator);\n```\n\nMost `Navigator` classes have a nested destination subclass. This subclass can\nbe used to specify additional attributes unique to your destination. For more\ninformation about destination subclasses, see the reference documentation for\nthe appropriate [`Navigator`](/reference/androidx/navigation/Navigator)\nclass.\n\nAdditional resources\n--------------------\n\nTo learn more about navigation, see the following\nadditional resources.\n\n\u003cbr /\u003e\n\n### Codelabs\n\n\u003cbr /\u003e\n\n- [Learn Jetpack Navigation codelab](https://codelabs.developers.google.com/codelabs/android-navigation/index.html?index=..%2F..%2Findex#0)\n\n\u003cbr /\u003e\n\n### Videos\n\n\u003cbr /\u003e\n\n- [Android Jetpack: Manage UI navigation with Navigation Controller](https://www.youtube.com/watch?v=8GCXtCjtg40)"]]