新しいデスティネーション タイプのサポートを追加する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
NavController
タイプは 1 つ以上の Navigator
オブジェクトを使用してナビゲーション処理を実行します。デフォルトでは、NavController
は、ActivityNavigator
クラスとその ActivityNavigator.Destination
ネストクラスを使用して別のアクティビティに移動することにより、ナビゲーション グラフを離れることをサポートしています。
他のタイプのデスティネーションに移動するには、Navigator
オブジェクトを 1 つ以上 NavController
に追加する必要があります。たとえば、フラグメントをデスティネーションとして使用する場合、NavHostFragment
は、FragmentNavigator
クラスをその NavController
に自動的に追加します。
新しい Navigator
オブジェクトを NavController
に追加するには、getNavigatorProvider()
メソッドの後に addNavigator()
メソッドを使用します。
次のコード例では、CustomNavigator
オブジェクトを NavController
に追加しています。
Kotlin
val customNavigator = CustomNavigator()
navController.navigatorProvider += customNavigator
Java
CustomNavigator customNavigator = new CustomNavigator();
navController.getNavigatorProvider().addNavigator(customNavigator);
ほとんどの Navigator
クラスには、ネスト デスティネーション サブクラスがあります。このサブクラスを使用することで、デスティネーション固有の追加属性を指定できます。デスティネーション サブクラスの詳細については、各 Navigator
クラスのリファレンス ドキュメントをご覧ください。
参考情報
ナビゲーションについて詳しくは、以下の参考情報をご確認ください。
Codelab
動画
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[null,null,["最終更新日 2025-07-27 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)"]]