第二个 Android 11 开发者预览版现已推出,快来测试并分享您的反馈吧

DynamicGraphNavigator

class DynamicGraphNavigator : NavGraphNavigator
kotlin.Any
   ↳ androidx.navigation.Navigator<androidx.navigation.NavGraph>
   ↳ androidx.navigation.NavGraphNavigator
   ↳ androidx.navigation.dynamicfeatures.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 classes

The NavGraph for dynamic features.

Public constructors

<init>(navigatorProvider: NavigatorProvider, installManager: DynamicInstallManager)

Navigator for graphs in dynamic feature modules.

Public methods

DynamicGraphNavigator.DynamicNavGraph

Create a destination for the DynamicNavGraph.

Unit
installDefaultProgressDestination(progressDestinationSupplier: () -> NavDestination)

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

NavDestination?
navigate(destination: NavGraph, args: Bundle?, navOptions: NavOptions?, navigatorExtras: Navigator.Extras?)

Navigate to a destination.

Unit
onRestoreState(savedState: Bundle)

Bundle?

Inherited functions

Public constructors

<init>

DynamicGraphNavigator(
    navigatorProvider: NavigatorProvider,
    installManager: DynamicInstallManager)

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.

Public methods

createDestination

fun createDestination(): DynamicGraphNavigator.DynamicNavGraph

Create a destination for the DynamicNavGraph.

Return
The created graph.

installDefaultProgressDestination

fun installDefaultProgressDestination(progressDestinationSupplier: () -> NavDestination): Unit

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
progressDestinationSupplier: () -> NavDestination The default progress destination supplier.

navigate

fun navigate(
    destination: NavGraph,
    args: Bundle?,
    navOptions: NavOptions?,
    navigatorExtras: Navigator.Extras?
): NavDestination?

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

fun onRestoreState(savedState: Bundle): Unit

onSaveState

fun onSaveState(): Bundle?