NavHost
public
interface
NavHost
androidx.navigation.NavHost |
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:
- Handle
saving
andrestoring
their controller's state - Call
Navigation.setViewNavController(View, NavController)
on their root view - Route system Back button events to the NavController either by manually calling
NavController.popBackStack()
or by callingNavHostController.setOnBackPressedDispatcher(androidx.activity.OnBackPressedDispatcher)
when constructing the NavController.
- Call
NavHostController.setLifecycleOwner(LifecycleOwner)
to associate the NavController with a specific Lifecycle. - Call
NavHostController.setViewModelStore(ViewModelStore)
to enable usage ofNavController.getViewModelStoreOwner(int)
and navigation graph scoped ViewModels.
Summary
Public methods | |
---|---|
abstract
NavController
|
getNavController()
Returns the |
Public methods
getNavController
public abstract NavController getNavController ()
Returns the navigation controller
for this navigation host.
Returns | |
---|---|
NavController |
this host's navigation controller |