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 |
|
final SavedState |
The arguments used for this entry. |
@NonNull CreationExtras |
Returns the default |
@NonNull ViewModelProvider.Factory |
Returns the default |
final @NonNull NavDestination |
The destination associated with this entry |
final @NonNull String |
getId()The unique ID that serves as the identity of this entry |
@NonNull Lifecycle |
{@inheritDoc} |
final @NonNull SavedStateHandle |
The |
@NonNull SavedStateRegistry |
The |
@NonNull ViewModelStore |
{@inheritDoc} |
int |
hashCode() |
@NonNull String |
toString() |
Extension functions |
|
|---|---|
final @NonNull T |
<T extends Object> NavBackStackEntryKt.toRoute(Returns route as an object of type |
final @NonNull T |
<T extends Object> NavBackStackEntryKt.toRoute(Returns route as an object of type |
Public methods
getArguments
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()
Returns the default CreationExtras that should be passed into ViewModelProvider.Factory.create when no overriding CreationExtras were passed to the ViewModelProvider constructors.
getDefaultViewModelProviderFactory
public @NonNull ViewModelProvider.Factory getDefaultViewModelProviderFactory()
Returns the default ViewModelProvider.Factory that should be used when no custom Factory is provided to the ViewModelProvider constructors.
getDestination
public final @NonNull NavDestination getDestination()
The destination associated with this entry
| Returns | |
|---|---|
@NonNull NavDestination |
The destination that is currently visible to users |
getLifecycle
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
@MainThread
public final @NonNull SavedStateHandle getSavedStateHandle()
The SavedStateHandle for this entry.
getSavedStateRegistry
public @NonNull SavedStateRegistry getSavedStateRegistry()
The SavedStateRegistry owned by this SavedStateRegistryOwner
getViewModelStore
public @NonNull ViewModelStore getViewModelStore()
{@inheritDoc}
| Throws | |
|---|---|
kotlin.IllegalStateException |
if called before the |
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 |
| Returns | |
|---|---|
@NonNull T |
A new instance of this entry's |
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 |
| Returns | |
|---|---|
@NonNull T |
A new instance of this entry's |