ActivityNavigator

public class ActivityNavigator extends Navigator

Object
   ↳ Navigator
     ↳ ActivityNavigator
Known direct subclasses
DynamicActivityNavigator

Dynamic feature navigator for Activity destinations.


ActivityNavigator implements cross-activity navigation.

Summary

Nested types

ActivityNavigator.Companion
ActivityNavigator.Destination

NavDestination for activity navigation

ActivityNavigator.Extras

Extras that can be passed to ActivityNavigator to customize what ActivityOptionsCompat and flags are passed through to the call to ActivityCompat.startActivity.

ActivityNavigator.Extras.Builder

Builder for constructing new Extras instances.

Public fields

final @NonNull Context
final boolean

Whether this Navigator is actively being used by a NavController.

Public constructors

Public methods

@NonNull ActivityNavigator.Destination

Construct a new NavDestination associated with this Navigator.

@Nullable NavDestination
navigate(
    @NonNull ActivityNavigator.Destination destination,
    @Nullable Bundle args,
    @Nullable NavOptions navOptions,
    @Nullable Navigator.Extras navigatorExtras
)

Navigate to a destination.

boolean

Attempt to pop this navigator's back stack, performing the appropriate navigation.

Inherited methods

From class Navigator
void
navigate(
    @NonNull List<@NonNull NavBackStackEntry> entries,
    @Nullable NavOptions navOptions,
    @Nullable Navigator.Extras navigatorExtras
)

Navigate to a destination.

@CallSuper void

Indicator that this Navigator is actively being used by a NavController.

void

Informational callback indicating that the given backStackEntry has been affected by a NavOptions.shouldLaunchSingleTop operation.

void

Restore any state previously saved in onSaveState.

@Nullable Bundle

Called to ask for a Bundle representing the Navigator's state.

void
popBackStack(@NonNull NavBackStackEntry popUpTo, boolean savedState)

Attempt to pop this navigator's back stack, performing the appropriate navigation.

Public fields

context

@NonNull
public final @NonNull Context context

isAttached

@NonNull
public final boolean isAttached

Whether this Navigator is actively being used by a NavController.

This is set to true when onAttach is called.

Public constructors

ActivityNavigator

@NonNull
public final ActivityNavigator(@NonNull Context context)

Public methods

createDestination

@NonNull
public ActivityNavigator.Destination createDestination()

Construct a new NavDestination associated with this Navigator.

Any initialization of the destination should be done in the destination's constructor as it is not guaranteed that every destination will be created through this method.

Returns
ActivityNavigator.Destination

a new NavDestination

@Nullable
public NavDestination navigate(
    @NonNull ActivityNavigator.Destination destination,
    @Nullable Bundle args,
    @Nullable NavOptions navOptions,
    @Nullable Navigator.Extras navigatorExtras
)

Navigate to a destination.

Requests navigation to a given destination associated with this navigator in the navigation graph. This method generally should not be called directly; NavController will delegate to it when appropriate.

Parameters
@NonNull ActivityNavigator.Destination destination

destination node to navigate to

@Nullable Bundle args

arguments to use for navigation

@Nullable NavOptions navOptions

additional options for navigation

@Nullable Navigator.Extras navigatorExtras

extras unique to your Navigator.

Returns
NavDestination

The NavDestination that should be added to the back stack or null if no change was made to the back stack (i.e., in cases of single top operations where the destination is already on top of the back stack).

Throws
kotlin.IllegalArgumentException

if the given destination has no Intent

popBackStack

@NonNull
public boolean popBackStack()

Attempt to pop this navigator's back stack, performing the appropriate navigation.

Implementations should return true if navigation was successful. Implementations should return false if navigation could not be performed, for example if the navigator's back stack was empty.

Returns
boolean

true if pop was successful