FragmentNavigator
@Navigator.Name(value = "fragment")
public class FragmentNavigator extends Navigator
DynamicFragmentNavigator |
The |
Navigator that navigates through fragment transactions. Every destination using this Navigator must set a valid Fragment class name with android:name or Destination.setClassName.
The current Fragment from FragmentNavigator's perspective can be retrieved by calling FragmentManager.getPrimaryNavigationFragment with the FragmentManager passed to this FragmentNavigator.
Note that the default implementation does Fragment transactions asynchronously, so the current Fragment will not be available immediately (i.e., in callbacks to NavController.OnDestinationChangedListener).
FragmentNavigator respects Log.isLoggable for debug logging, allowing you to use adb shell setprop log.tag.FragmentNavigator VERBOSE.
Summary
Nested types |
|---|
@NavDestination.ClassType(value = Fragment)NavDestination specific to |
public final class FragmentNavigator.Extras implements Navigator.ExtrasExtras that can be passed to FragmentNavigator to enable Fragment specific behavior |
public final class FragmentNavigator.Extras.BuilderBuilder for constructing new |
Public constructors |
|---|
FragmentNavigator( |
Public methods |
|
|---|---|
@NonNull FragmentNavigator.Destination |
|
@NonNull Fragment |
This method is deprecated. Set a custom {@link androidx.fragment.app.FragmentFactory} via {@link FragmentManager#setFragmentFactory(FragmentFactory)} to control instantiation of Fragments. |
void |
navigate({@inheritDoc} |
void |
onAttach(@NonNull NavigatorState state) |
void |
onLaunchSingleTop(@NonNull NavBackStackEntry backStackEntry){@inheritDoc} |
void |
onRestoreState(@NonNull Bundle savedState) |
Bundle |
|
void |
popBackStack(@NonNull NavBackStackEntry popUpTo, boolean savedState){@inheritDoc} |
Inherited methods |
||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
FragmentNavigator
public FragmentNavigator(
@NonNull Context context,
@NonNull FragmentManager fragmentManager,
int containerId
)
Public methods
public @NonNull FragmentinstantiateFragment(
@NonNull Context context,
@NonNull FragmentManager fragmentManager,
@NonNull String className,
Bundle args
)
Instantiates the Fragment via the FragmentManager's androidx.fragment.app.FragmentFactory.
Note that this method is not responsible for calling Fragment.setArguments on the returned Fragment instance.
| Parameters | |
|---|---|
@NonNull Context context |
Context providing the correct |
@NonNull FragmentManager fragmentManager |
FragmentManager the Fragment will be added to |
@NonNull String className |
The Fragment to instantiate |
Bundle args |
The Fragment's arguments, if any |
navigate
public void navigate(
@NonNull List<@NonNull NavBackStackEntry> entries,
NavOptions navOptions,
Navigator.Extras navigatorExtras
)
{@inheritDoc}
This method should always call FragmentTransaction.setPrimaryNavigationFragment so that the Fragment associated with the new destination can be retrieved with FragmentManager.getPrimaryNavigationFragment.
Note that the default implementation commits the new Fragment asynchronously, so the new Fragment is not instantly available after this call completes.
This call will be ignored if the FragmentManager state has already been saved.
onLaunchSingleTop
public void onLaunchSingleTop(@NonNull NavBackStackEntry backStackEntry)
{@inheritDoc}
This method should always call FragmentTransaction.setPrimaryNavigationFragment so that the Fragment associated with the new destination can be retrieved with FragmentManager.getPrimaryNavigationFragment.
Note that the default implementation commits the new Fragment asynchronously, so the new Fragment is not instantly available after this call completes.
This call will be ignored if the FragmentManager state has already been saved.
popBackStack
public void popBackStack(@NonNull NavBackStackEntry popUpTo, boolean savedState)
{@inheritDoc}
This method must call FragmentTransaction.setPrimaryNavigationFragment if the pop succeeded so that the newly visible Fragment can be retrieved with FragmentManager.getPrimaryNavigationFragment.
Note that the default implementation pops the Fragment asynchronously, so the newly visible Fragment from the back stack is not instantly available after this call completes.