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

Public methods

boolean
equals(Object other)
final SavedState

The arguments used for this entry.

@NonNull CreationExtras
@NonNull ViewModelProvider.Factory
final @NonNull NavDestination

The destination associated with this entry

final @NonNull String

The unique ID that serves as the identity of this entry

@NonNull Lifecycle

{@inheritDoc}

final @NonNull SavedStateHandle

The SavedStateHandle for this entry.

@NonNull SavedStateRegistry
@NonNull ViewModelStore

{@inheritDoc}

int
@NonNull String

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

getDefaultViewModelProviderFactory

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

getDestination

Added in 2.2.0
public final @NonNull NavDestination getDestination()

The destination associated with this entry

Returns
@NonNull NavDestination

The destination that is currently visible to users

getId

public final @NonNull String getId()

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

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