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 |
Public fields
navController
@NonNull
public abstract @NonNull NavController navController
The navigation controller for this navigation host.