NavBackStackEntry



Representation of an entry in the back stack of a androidx.navigation.NavController. The Lifecycle, ViewModelStore, and SavedStateRegistry provided via this object are valid for the lifetime of this destination on the back stack: when this destination is popped off the back stack, the lifecycle will be destroyed, state will no longer be saved, and ViewModels will be cleared.

Summary

Public properties

SavedState?

The arguments used for this entry.

Cmn
android
open CreationExtras

Returns the default CreationExtras that should be passed into ViewModelProvider.Factory.create when no overriding CreationExtras were passed to the ViewModelProvider constructors.

Cmn
open ViewModelProvider.Factory

Returns the default ViewModelProvider.Factory that should be used when no custom Factory is provided to the ViewModelProvider constructors.

Cmn
android
NavDestination

The destination associated with this entry

Cmn
android
String

The unique ID that serves as the identity of this entry

Cmn
android
open Lifecycle

{@inheritDoc}

Cmn
android
SavedStateHandle

The SavedStateHandle for this entry.

Cmn
android
open SavedStateRegistry

The SavedStateRegistry owned by this SavedStateRegistryOwner

Cmn
android
open ViewModelStore

{@inheritDoc}

Cmn
android

Extension functions

inline T

Returns route as an object of type T

Cmn
T
<T : Any?> NavBackStackEntry.toRoute(route: KClass<*>)

Returns route as an object of type T

Cmn
Unit
@Composable
NavBackStackEntry.LocalOwnersProvider(
    saveableStateHolder: SaveableStateHolder,
    content: @Composable () -> Unit
)

Provides this as LocalViewModelStoreOwner, LocalLifecycleOwner and LocalSavedStateRegistryOwner to the content and saves the content's saveable states with the given saveableStateHolder.

Cmn
android

Inherited properties

From androidx.lifecycle.HasDefaultViewModelProviderFactory
open CreationExtras

Returns the default CreationExtras that should be passed into ViewModelProvider.Factory.create when no overriding CreationExtras were passed to the ViewModelProvider constructors.

android

Public properties

arguments

val argumentsSavedState?

The arguments used for this entry. Note that the arguments of a NavBackStackEntry are immutable and defined when you navigate() to the destination - changes you make to this SavedState will not be reflected in future calls to this property.

Returns
SavedState?

The arguments used when this entry was created

defaultViewModelCreationExtras

open val defaultViewModelCreationExtrasCreationExtras

Returns the default CreationExtras that should be passed into ViewModelProvider.Factory.create when no overriding CreationExtras were passed to the ViewModelProvider constructors.

defaultViewModelProviderFactory

open val defaultViewModelProviderFactoryViewModelProvider.Factory

Returns the default ViewModelProvider.Factory that should be used when no custom Factory is provided to the ViewModelProvider constructors.

destination

val destinationNavDestination

The destination associated with this entry

Returns
NavDestination

The destination that is currently visible to users

id

val idString

The unique ID that serves as the identity of this entry

Returns
String

the unique ID of this entry

lifecycle

open val lifecycleLifecycle

{@inheritDoc}

If the androidx.navigation.NavHost has not called androidx.navigation.NavHostController.setLifecycleOwner, the Lifecycle will be capped at Lifecycle.State.CREATED.

savedStateHandle

val savedStateHandleSavedStateHandle

The SavedStateHandle for this entry.

savedStateRegistry

open val savedStateRegistrySavedStateRegistry

The SavedStateRegistry owned by this SavedStateRegistryOwner

viewModelStore

open val viewModelStoreViewModelStore

{@inheritDoc}

Extension functions

inline fun <T : Any?> NavBackStackEntry.toRoute(): T

Returns route as an object of type T

Extrapolates arguments from NavBackStackEntry.arguments and recreates object T

Parameters
<T : Any?>

the entry's NavDestination.route as a KClass

Returns
T

A new instance of this entry's NavDestination.route as an object of type T

fun <T : Any?> NavBackStackEntry.toRoute(route: KClass<*>): T

Returns route as an object of type T

Extrapolates arguments from NavBackStackEntry.arguments and recreates object T

Parameters
route: KClass<*>

the entry's NavDestination.route as a KClass

Returns
T

A new instance of this entry's NavDestination.route as an object of type T

LocalOwnersProvider

@Composable
fun NavBackStackEntry.LocalOwnersProvider(
    saveableStateHolder: SaveableStateHolder,
    content: @Composable () -> Unit
): Unit

Provides this as LocalViewModelStoreOwner, LocalLifecycleOwner and LocalSavedStateRegistryOwner to the content and saves the content's saveable states with the given saveableStateHolder.

Parameters
saveableStateHolder: SaveableStateHolder

The SaveableStateHolder that holds the saved states. The same holder should be used for all NavBackStackEntrys in the encapsulating Composable and the holder should be hoisted.

content: @Composable () -> Unit

The content Composable