FragmentNavigator

public class FragmentNavigator
extends Navigator<FragmentNavigator.Destination>

java.lang.Object
   ↳ androidx.navigation.Navigator<androidx.navigation.fragment.FragmentNavigator.Destination>
     ↳ androidx.navigation.fragment.FragmentNavigator


Navigator that navigates through fragment transactions. Every destination using this Navigator must set a valid Fragment class name with android:name or FragmentNavigator.Destination.setFragmentClass(Class).

Summary

Nested classes

class FragmentNavigator.Destination

NavDestination specific to FragmentNavigator  

Inherited constants

Public constructors

FragmentNavigator(Context context, FragmentManager manager, int containerId)

Public methods

FragmentNavigator.Destination createDestination()

Construct a new NavDestination associated with this Navigator.

void navigate(FragmentNavigator.Destination destination, Bundle args, NavOptions navOptions)

Navigate to a destination.

void onActive()

Called when the number of listeners change from 0 to 1

void onInactive()

Called when the number of listeners change from 1 to 0

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

FragmentNavigator

public FragmentNavigator (Context context, 
                FragmentManager manager, 
                int containerId)

Parameters
context Context

manager FragmentManager

containerId int

Public methods

createDestination

public FragmentNavigator.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
FragmentNavigator.Destination a new NavDestination

navigate

public void navigate (FragmentNavigator.Destination destination, 
                Bundle args, 
                NavOptions navOptions)

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.

Implementations should dispatchOnNavigatorNavigated(int, int) to notify listeners of the resulting navigation destination.

Parameters
destination FragmentNavigator.Destination: destination node to navigate to

args Bundle: arguments to use for navigation

navOptions NavOptions: additional options for navigation

onActive

public void onActive ()

Called when the number of listeners change from 0 to 1

onInactive

public void onInactive ()

Called when the number of listeners change from 1 to 0

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) 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 dispatchOnNavigatorNavigated(int, int) to notify listeners of the resulting navigation destination and 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