NavHost
public interface NavHost
NavHostFragment |
NavHostFragment provides an area within your layout for self-contained navigation to occur. |
DynamicNavHostFragment |
The |
A host is a single context or container for navigation via a NavController.
It is strongly recommended to construct the nav controller by instantiating a NavHostController, which offers additional APIs specifically for a NavHost. The NavHostController should still only be externally accessible as a NavController, rather than directly exposing it as a NavHostController.
Navigation hosts must:
-
Call Navigation.setViewNavController on their root view
-
Route system Back button events to the NavController either by manually calling
NavController.popBackStackor by calling NavHostController.setOnBackPressedDispatcher when constructing the NavController.
Optionally, a navigation host should consider calling:
-
Call
NavHostController.setLifecycleOwnerto associate the NavController with a specific Lifecycle. -
Call
NavHostController.setViewModelStoreto enable usage of NavController.getViewModelStoreOwner and navigation graph scoped ViewModels.
Summary
Public methods |
|
|---|---|
abstract @NonNull NavController |
The |
Extension functions |
|
|---|---|
default final @NonNull NavGraph |
NavHostKt.This method is deprecated. Use routes to create your NavGraph instead |
default final @NonNull NavGraph |
NavHostKt.This method is deprecated. Use routes to create your dynamic NavGraph instead |
default final @NonNull NavGraph |
NavHostKt.createGraph(Construct a new |
default final @NonNull NavGraph |
NavHostKt.createGraph(Construct a new |
default final @NonNull NavGraph |
NavHostKt.createGraph(Construct a new |
default final @NonNull NavGraph |
NavHostKt.createGraph(Construct a new |
default final @NonNull NavGraph |
NavHostKt.createGraph(Construct a new |
default final @NonNull NavGraph |
NavHostKt.createGraph(Construct a new |
Public methods
getNavController
abstract @NonNull NavController getNavController()
The navigation controller for this navigation host.
Extension functions
NavHostKt.createGraph
default final @NonNull NavGraph NavHostKt.createGraph(
@NonNull NavHost receiver,
@IdRes int id,
@IdRes int startDestination,
@NonNull Function1<@NonNull NavGraphBuilder, Unit> builder
)
Construct a new NavGraph
NavHostKt.createGraph
default final @NonNull NavGraph NavHostKt.createGraph(
@NonNull NavHost receiver,
@IdRes int id,
@IdRes int startDestination,
@NonNull Function1<@NonNull DynamicNavGraphBuilder, Unit> builder
)
Construct a new androidx.navigation.NavGraph that supports dynamic navigation destinations
NavHostKt.createGraph
default final @NonNull NavGraph NavHostKt.createGraph(
@NonNull NavHost receiver,
@NonNull String startDestination,
String route,
@NonNull Function1<@NonNull NavGraphBuilder, Unit> builder
)
Construct a new NavGraph
NavHostKt.createGraph
default final @NonNull NavGraph NavHostKt.createGraph(
@NonNull NavHost receiver,
@NonNull String startDestination,
String route,
@NonNull Function1<@NonNull DynamicNavGraphBuilder, Unit> builder
)
Construct a new androidx.navigation.NavGraph that supports dynamic navigation destinations
NavHostKt.createGraph
default final @NonNull NavGraph NavHostKt.createGraph(
@NonNull NavHost receiver,
@NonNull Object startDestination,
KClass<@NonNull ?> route,
@NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap,
@NonNull Function1<@NonNull NavGraphBuilder, Unit> builder
)
Construct a new NavGraph
| Parameters | |
|---|---|
@NonNull Object startDestination |
the starting destination's route from an Object for this NavGraph. The respective NavDestination must be added as a |
KClass<@NonNull ?> route |
the graph's unique route from a |
@NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap |
A mapping of KType to custom NavType<*> in the |
@NonNull Function1<@NonNull NavGraphBuilder, Unit> builder |
the builder used to construct the graph |
NavHostKt.createGraph
default final @NonNull NavGraph NavHostKt.createGraph(
@NonNull NavHost receiver,
@NonNull Object startDestination,
KClass<@NonNull ?> route,
@NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap,
@NonNull Function1<@NonNull DynamicNavGraphBuilder, Unit> builder
)
Construct a new androidx.navigation.NavGraph that supports dynamic navigation destinations
| Parameters | |
|---|---|
@NonNull Object startDestination |
the starting destination's route from an Object for this NavGraph. The respective NavDestination must be added as a |
KClass<@NonNull ?> route |
the graph's unique route from a |
@NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap |
A mapping of KType to custom NavType<*> in the |
@NonNull Function1<@NonNull DynamicNavGraphBuilder, Unit> builder |
the builder used to construct the graph |
NavHostKt.createGraph
default final @NonNull NavGraph NavHostKt.createGraph(
@NonNull NavHost receiver,
@NonNull KClass<@NonNull ?> startDestination,
KClass<@NonNull ?> route,
@NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap,
@NonNull Function1<@NonNull NavGraphBuilder, Unit> builder
)
Construct a new NavGraph
| Parameters | |
|---|---|
@NonNull KClass<@NonNull ?> startDestination |
the starting destination's route from a |
KClass<@NonNull ?> route |
the graph's unique route from a |
@NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap |
A mapping of KType to custom NavType<*> in the |
@NonNull Function1<@NonNull NavGraphBuilder, Unit> builder |
the builder used to construct the graph |
NavHostKt.createGraph
default final @NonNull NavGraph NavHostKt.createGraph(
@NonNull NavHost receiver,
@NonNull KClass<@NonNull ?> startDestination,
KClass<@NonNull ?> route,
@NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap,
@NonNull Function1<@NonNull DynamicNavGraphBuilder, Unit> builder
)
Construct a new androidx.navigation.NavGraph that supports dynamic navigation destinations
| Parameters | |
|---|---|
@NonNull KClass<@NonNull ?> startDestination |
the starting destination's route from a |
KClass<@NonNull ?> route |
the graph's unique route from a |
@NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap |
A mapping of KType to custom NavType<*> in the |
@NonNull Function1<@NonNull DynamicNavGraphBuilder, Unit> builder |
the builder used to construct the graph |