NavHost
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 |
Returns the |
Extension functions |
||
---|---|---|
From androidx.navigation
|
Public methods
getNavController
@NonNull abstract fun getNavController(): NavController
Returns the navigation controller
for this navigation host.
Return | |
---|---|
NavController: this host's navigation controller |