NavHost
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.setViewNavControlleron their root view -
Route system Back button events to the NavController either by manually calling
NavController.popBackStackor by callingNavHostController.setOnBackPressedDispatcherwhen 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 ofNavController.getViewModelStoreOwnerand navigation graph scoped ViewModels.
Summary
Public fields |
|
|---|---|
abstract @NonNull NavController |
The |
Extension functions |
|
|---|---|
final @NonNull NavGraph |
NavHostKt.This method is deprecated. Use routes to create your NavGraph instead |
final @NonNull NavGraph |
NavHostKt.createGraph(Construct a new |
final @NonNull NavGraph |
NavHostKt.This method is deprecated. Use routes to create your dynamic NavGraph instead |
final @NonNull NavGraph |
NavHostKt.createGraph(Construct a new |
Public fields
navController
@NonNull
public abstract @NonNull NavController navController
The navigation controller for this navigation host.
Extension functions
NavHostKt.createGraph
@NonNull
public final NavGraph NavHostKt.createGraph(
@NonNull NavHost receiver,
@IdRes int id,
@IdRes int startDestination,
@NonNull Function1<@NonNull NavGraphBuilder, Unit> builder
)
Construct a new NavGraph
NavHostKt.createGraph
@NonNull
public final NavGraph NavHostKt.createGraph(
@NonNull NavHost receiver,
@NonNull String startDestination,
@Nullable String route,
@NonNull Function1<@NonNull NavGraphBuilder, Unit> builder
)
Construct a new NavGraph
NavHostKt.createGraph
@NonNull
public final 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
@NonNull
public final NavGraph NavHostKt.createGraph(
@NonNull NavHost receiver,
@NonNull String startDestination,
@Nullable String route,
@NonNull Function1<@NonNull DynamicNavGraphBuilder, Unit> builder
)
Construct a new androidx.navigation.NavGraph that supports dynamic navigation destinations