A host is a single context or container for navigation via a
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
Navigation hosts must:
restoringtheir controller's state
Navigation#setViewNavController(View, NavController)on their root view
- Route system Back button events to the NavController either by manually calling
NavController#popBackStack()or by calling
NavHostController#setOnBackPressedDispatcher(androidx.activity.OnBackPressedDispatcher)when constructing the NavController.
NavHostController#setLifecycleOwner(LifecycleOwner)to associate the NavController with a specific Lifecycle.
NavHostController#setViewModelStore(ViewModelStore)to enable usage of
NavController#getViewModelStore(int)and navigation graph scoped ViewModels.