NavBackStackEntry


public final class NavBackStackEntry implements 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

Extension functions

final @NonNull T

Returns route as an object of type T

final @NonNull T
<T extends Object> NavBackStackEntryKt.toRoute(
 @NonNull NavBackStackEntry receiver,
 @NonNull KClass<@NonNull ?> route
)

Returns route as an object of type T

Public methods

equals

public boolean equals(Object other)

getArguments

Added in 2.2.0
public final SavedStategetArguments()

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

getDefaultViewModelCreationExtras

public @NonNull CreationExtrasgetDefaultViewModelCreationExtras()

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

getDefaultViewModelProviderFactory

Added in 2.2.0
public @NonNull ViewModelProvider.FactorygetDefaultViewModelProviderFactory()

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

getDestination

Added in 2.2.0
public final @NonNull NavDestinationgetDestination()

The destination associated with this entry

Returns
@NonNull NavDestination

The destination that is currently visible to users

getId

public final @NonNull StringgetId()

The unique ID that serves as the identity of this entry

Returns
@NonNull String

the unique ID of this entry

getLifecycle

Added in 2.2.0
public @NonNull LifecyclegetLifecycle()

{@inheritDoc}

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

getSavedStateHandle

Added in 2.3.0
@MainThread
public final @NonNull SavedStateHandlegetSavedStateHandle()

The SavedStateHandle for this entry.

getSavedStateRegistry

Added in 2.2.0
public @NonNull SavedStateRegistrygetSavedStateRegistry()

The SavedStateRegistry owned by this SavedStateRegistryOwner

getViewModelStore

Added in 2.2.0
public @NonNull ViewModelStoregetViewModelStore()

{@inheritDoc}

hashCode

public int hashCode()

hashCode

public int hashCode()

toString

public @NonNull StringtoString()

toString

public @NonNull StringtoString()

Extension functions

NavBackStackEntryKt.toRoute

public final @NonNull T <T extends Object> NavBackStackEntryKt.toRoute(
 @NonNull NavBackStackEntry receiver
)

Returns route as an object of type T

Extrapolates arguments from NavBackStackEntry.arguments and recreates object T

Parameters
<T extends Object>

the entry's NavDestination.route as a KClass

Returns
@NonNull T

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

NavBackStackEntryKt.toRoute

public final @NonNull T <T extends Object> NavBackStackEntryKt.toRoute(
 @NonNull NavBackStackEntry receiver,
 @NonNull KClass<@NonNull ?> route
)

Returns route as an object of type T

Extrapolates arguments from NavBackStackEntry.arguments and recreates object T

Parameters
@NonNull KClass<@NonNull ?> route

the entry's NavDestination.route as a KClass