Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

NavGraphNavigator

public class NavGraphNavigator
extends Navigator<NavGraph>

java.lang.Object
   ↳ androidx.navigation.Navigator<androidx.navigation.NavGraph>
     ↳ androidx.navigation.NavGraphNavigator


A Navigator built specifically for NavGraph elements. Handles navigating to the correct destination when the NavGraph is the target of navigation actions.

Summary

Public constructors

NavGraphNavigator(NavigatorProvider navigatorProvider)

Construct a Navigator capable of routing incoming navigation requests to the proper destination within a NavGraph.

Public methods

NavGraph createDestination()

Creates a new NavGraph associated with this navigator.

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

Navigate to a destination.

void onRestoreState(Bundle savedState)

Restore any state previously saved in onSaveState().

Bundle onSaveState()

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

boolean popBackStack()

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

Inherited methods

Public constructors

public NavGraphNavigator (NavigatorProvider navigatorProvider)

Construct a Navigator capable of routing incoming navigation requests to the proper destination within a NavGraph.

Parameters
navigatorProvider NavigatorProvider: NavigatorProvider used to retrieve the correct Navigator to navigate to the start destination

Public methods

createDestination

public NavGraph createDestination ()

Creates a new NavGraph associated with this navigator.

Returns
NavGraph a new NavDestination

public NavDestination navigate (NavGraph destination, 
                Bundle args, 
                NavOptions navOptions, 
                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
destination NavGraph: destination node to navigate to

args Bundle: arguments to use for navigation

navOptions NavOptions: additional options for navigation

navigatorExtras Navigator.Extras: 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).

onRestoreState

public void onRestoreState (Bundle savedState)

Restore any state previously saved in onSaveState(). This will be called before any calls to navigate(NavDestination, Bundle, NavOptions, Navigator.Extras) 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
savedState Bundle: The state previously saved

onSaveState

public Bundle onSaveState ()

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

Returns
Bundle

popBackStack

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