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
<T extends Object> NavBackStackEntryKt.toRoute(
    @NonNull NavBackStackEntry receiver
)

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 SavedState getArguments()

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 CreationExtras getDefaultViewModelCreationExtras()

The default CreationExtras to pass into ViewModelProvider.Factory.create when no overriding CreationExtras are provided.

getDefaultViewModelProviderFactory

Added in 2.2.0
public @NonNull ViewModelProvider.Factory getDefaultViewModelProviderFactory()

The default ViewModelProvider.Factory to use when no custom ViewModelProvider.Factory is provided to the ViewModelProvider.

getDestination

Added in 2.2.0
public final @NonNull NavDestination getDestination()

getId

public final @NonNull String getId()

getLifecycle

Added in 2.2.0
public @NonNull Lifecycle getLifecycle()

{@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 SavedStateHandle getSavedStateHandle()

The SavedStateHandle for this entry.

getSavedStateRegistry

Added in 2.2.0
public @NonNull SavedStateRegistry getSavedStateRegistry()

The SavedStateRegistry owned by this SavedStateRegistryOwner.

getViewModelStore

Added in 2.2.0
public @NonNull ViewModelStore getViewModelStore()

{@inheritDoc}

hashCode

public int hashCode()

toString

public @NonNull String toString()

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

Returns
@NonNull T

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