NavBackStackEntry

class NavBackStackEntry : LifecycleOwner, ViewModelStoreOwner, HasDefaultViewModelProviderFactory, SavedStateRegistryOwner


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 functions

open operator Boolean
equals(other: Any?)
open Int
open String

Public properties

Bundle?

The arguments used for this entry.

open CreationExtras

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

open ViewModelProvider.Factory

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

NavDestination

The destination associated with this entry

String

The unique ID that serves as the identity of this entry

open Lifecycle

{@inheritDoc}

SavedStateHandle

The SavedStateHandle for this entry.

open SavedStateRegistry

The SavedStateRegistry owned by this SavedStateRegistryOwner

open ViewModelStore

The owned ViewModelStore

Extension functions

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.

Public functions

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

toString

open fun toString(): String

Public properties

arguments

Added in 2.2.0
val argumentsBundle?

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 Bundle will not be reflected in future calls to this property.

Returns
Bundle?

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

Added in 2.2.0
open val defaultViewModelProviderFactoryViewModelProvider.Factory

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

destination

Added in 2.2.0
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

Added in 2.2.0
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

Added in 2.3.0
val savedStateHandleSavedStateHandle

The SavedStateHandle for this entry.

savedStateRegistry

Added in 2.2.0
open val savedStateRegistrySavedStateRegistry

The SavedStateRegistry owned by this SavedStateRegistryOwner

viewModelStore

Added in 2.2.0
open val viewModelStoreViewModelStore

The owned ViewModelStore

Extension functions

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