Google se compromete a impulsar la igualdad racial para las comunidades afrodescendientes. Obtén información al respecto.

NavHostController

open class NavHostController : NavController
kotlin.Any
   ↳ androidx.navigation.NavController
   ↳ androidx.navigation.NavHostController

Subclass of NavController that offers additional APIs for use by a NavHost to connect the NavController to external dependencies.

Apps should generally not construct controllers, instead obtain a relevant controller directly from a navigation host via NavHost#getNavController() or by using one of the utility methods on the Navigation class.

Summary

Inherited constants
Public constructors
<init>(@NonNull context: Context)

Construct a new controller for a given Context suitable for use in a NavHost.

Public methods
Unit

Set whether the NavController should handle the system Back button events via the registered OnBackPressedDispatcher.

Unit

Sets the host's LifecycleOwner.

Unit

Sets the host's OnBackPressedDispatcher.

Unit
setViewModelStore(@NonNull viewModelStore: ViewModelStore)

Sets the host's ViewModelStore used by the NavController to store ViewModels at the navigation graph level.

Inherited functions

Public constructors

<init>

NavHostController(@NonNull context: Context)

Construct a new controller for a given Context suitable for use in a NavHost. Controllers should not be used outside of their context and retain a hard reference to the context supplied. If you need a global controller, pass Context#getApplicationContext().

Note that controllers that are not constructed with an Activity context (or a wrapped activity context) will only be able to navigate to new tasks or new document tasks when navigating to new activities.

Parameters
context Context: context for this controller

Public methods

enableOnBackPressed

fun enableOnBackPressed(enabled: Boolean): Unit

Set whether the NavController should handle the system Back button events via the registered OnBackPressedDispatcher.

Parameters
enabled Boolean: True if the NavController should handle system Back button events.

setLifecycleOwner

fun setLifecycleOwner(@NonNull owner: LifecycleOwner): Unit

Sets the host's LifecycleOwner.

Parameters
owner LifecycleOwner: The