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
open ViewModelProvider.Factory
NavDestination

The destination associated with this entry

String

The unique ID that serves as the identity of this entry

open Lifecycle

{@inheritDoc}

<Error class: unknown class>

The SavedStateHandle for this entry.

open SavedStateRegistry
open ViewModelStore

Extension functions

inline T

Returns route as an object of type T

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

defaultViewModelProviderFactory

Added in 2.2.0
open val defaultViewModelProviderFactoryViewModelProvider.Factory

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 savedStateHandle<Error class: unknown class>

The SavedStateHandle for this entry.

savedStateRegistry

Added in 2.2.0
open val savedStateRegistrySavedStateRegistry

viewModelStore

Added in 2.2.0
open val viewModelStoreViewModelStore

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

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