DynamicGraphNavigator

public final class DynamicGraphNavigator extends Navigator, NavGraphNavigator

Object
   ↳ Navigator
     ↳ NavGraphNavigator
       ↳ DynamicGraphNavigator

Navigator for graphs in dynamic feature modules.

This class handles navigating to a progress destination when the installation of a dynamic feature module is required. By default, the progress destination set by installDefaultProgressDestination will be used, but this can be overridden by setting the app:progressDestinationId attribute in your navigation XML file.

Summary

Nested types

DynamicGraphNavigator.DynamicNavGraph

The NavGraph for dynamic features.

Public fields

final boolean

Whether this Navigator is actively being used by a NavController.

Public constructors

DynamicGraphNavigator(
    @NonNull NavigatorProvider navigatorProvider,
    @NonNull DynamicInstallManager installManager
)

Public methods

@NonNull DynamicGraphNavigator.DynamicNavGraph

Create a destination for the DynamicNavGraph.

final void
installDefaultProgressDestination(
    @NonNull Function0<@NonNull NavDestination> progressDestinationSupplier
)

Installs the default progress destination to this graph via a lambda.

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

Navigate to a destination.

void

Restore any state previously saved in onSaveState.

@Nullable Bundle

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

Inherited methods

From class Navigator
@Nullable NavDestination
navigate(
    @NonNull NavGraph destination,
    @Nullable Bundle args,
    @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.

boolean

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

void
popBackStack(@NonNull NavBackStackEntry popUpTo, boolean savedState)

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

Public fields

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

DynamicGraphNavigator

public final DynamicGraphNavigator(
    @NonNull NavigatorProvider navigatorProvider,
    @NonNull DynamicInstallManager installManager
)

Public methods

createDestination

@NonNull
public DynamicGraphNavigator.DynamicNavGraph createDestination()

Create a destination for the DynamicNavGraph.

Returns
DynamicGraphNavigator.DynamicNavGraph

The created graph.

installDefaultProgressDestination

@NonNull
public final void installDefaultProgressDestination(
    @NonNull Function0<@NonNull NavDestination> progressDestinationSupplier
)

Installs the default progress destination to this graph via a lambda. This supplies a NavDestination to use when the actual destination is not installed at navigation time.

This must be called before you call androidx.navigation.NavController.setGraph to ensure that all DynamicNavGraph instances have the correct progress destination installed in onRestoreState.

Parameters
@NonNull Function0<@NonNull NavDestination> progressDestinationSupplier

The default progress destination supplier.

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

Navigate to a destination.

In case the destination module is installed the navigation will trigger directly. Otherwise the dynamic feature module is requested and navigation is postponed until the module has successfully been installed.

onRestoreState

@NonNull
public void onRestoreState(@NonNull Bundle savedState)

Restore any state previously saved in onSaveState. This will be called before any calls to navigate or popBackStack.

Calls to createDestination should not be dependent on any state restored here as createDestination can be called before the state is restored.

Parameters
@NonNull Bundle savedState

The state previously saved

onSaveState

@Nullable
public Bundle onSaveState()

Called to ask for a Bundle representing the Navigator's state. This will be restored in onRestoreState.