Google 致力于为黑人社区推动种族平等。查看具体举措

FragmentNavigator

open class FragmentNavigator : Navigator<FragmentNavigator.Destination!>
kotlin.Any
   ↳ 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 Destination#setClassName(String).

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).

Summary

Nested classes
open

NavDestination specific to FragmentNavigator

Extras that can be passed to FragmentNavigator to enable Fragment specific behavior

Public constructors
<init>(@NonNull context: Context, @NonNull manager: FragmentManager, containerId: Int)

Public methods
open FragmentNavigator.Destination

open Fragment
instantiateFragment(@NonNull context: Context, @NonNull fragmentManager: FragmentManager, @NonNull className: String, @Nullable args: Bundle?)

Instantiates the Fragment via the FragmentManager's androidx.fragment.app.FragmentFactory.

open NavDestination?
navigate(@NonNull destination: FragmentNavigator.Destination, @Nullable args: Bundle?, @Nullable navOptions: NavOptions?, @Nullable navigatorExtras: Navigator.Extras?)

Navigate to a destination.

open Unit
onRestoreState(@Nullable savedState: Bundle!)

open Bundle?

open Boolean

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

Public constructors

<init>

FragmentNavigator(
    @NonNull context: Context,
    @NonNull manager: FragmentManager,
    containerId: Int)

Public methods

createDestination

@NonNull open fun createDestination(): FragmentNavigator.Destination

instantiateFragment

@NonNull open fun instantiateFragment(
    @NonNull context: Context,
    @NonNull fragmentManager: FragmentManager,
    @NonNull className: String,
    @Nullable args: Bundle?
): Fragment

Deprecated: Set a custom androidx.fragment.app.FragmentFactory via FragmentManager#setFragmentFactory(FragmentFactory) to control instantiation of Fragments.

Instantiates the Fragment via the FragmentManager's androidx.fragment.app.FragmentFactory. Note that this method is not responsible for calling Fragment#setArguments(Bundle) on the returned Fragment instance.

Parameters
context Context: Context providing the correct ClassLoader
fragmentManager FragmentManager: FragmentManager the Fragment will be added to
className String: The Fragment to instantiate
args Bundle?: The Fragment's arguments, if any
Return
Fragment A new fragment instance.