FragmentController

public class FragmentController


Provides integration points with a FragmentManager for a fragment host.

It is the responsibility of the host to take care of the Fragment's lifecycle. The methods provided by FragmentController are for that purpose.

Summary

Public methods

@NonNull void

Attaches the host to the FragmentManager for this controller.

static @NonNull FragmentController

Returns a FragmentController.

@NonNull void

Moves all Fragments managed by the controller's FragmentManager into the activity created state.

@NonNull void

Lets all Fragments managed by the controller's FragmentManager know a configuration change occurred.

@NonNull boolean

Sends a context item selection event to the Fragments managed by the controller's FragmentManager.

@NonNull void

Moves all Fragments managed by the controller's FragmentManager into the create state.

@NonNull boolean
dispatchCreateOptionsMenu(
    @NonNull Menu menu,
    @NonNull MenuInflater inflater
)

Lets all Fragments managed by the controller's FragmentManager know they should create an options menu.

@NonNull void

Moves Fragments managed by the controller's FragmentManager into the destroy state.

@NonNull void

Moves all Fragments managed by the controller's FragmentManager into the destroy view state.

@NonNull void

Lets all Fragments managed by the controller's FragmentManager know the device is in a low memory condition.

@NonNull void
dispatchMultiWindowModeChanged(@NonNull boolean isInMultiWindowMode)

Lets all Fragments managed by the controller's FragmentManager know the multi-window mode of the activity changed.

@NonNull boolean

Sends an option item selection event to the Fragments managed by the controller's FragmentManager.

@NonNull void

Lets all Fragments managed by the controller's FragmentManager know their options menu has closed.

@NonNull void

Moves all Fragments managed by the controller's FragmentManager into the pause state.

@NonNull void
dispatchPictureInPictureModeChanged(
    @NonNull boolean isInPictureInPictureMode
)

Lets all Fragments managed by the controller's FragmentManager know the picture-in-picture mode of the activity changed.

@NonNull boolean

Lets all Fragments managed by the controller's FragmentManager know they should prepare their options menu for display.

@NonNull void

This method is deprecated.

This functionality has been rolled into dispatchStop.

@NonNull void

Moves all Fragments managed by the controller's FragmentManager into the resume state.

@NonNull void

Moves all Fragments managed by the controller's FragmentManager into the start state.

@NonNull void

Moves all Fragments managed by the controller's FragmentManager into the stop state.

@NonNull void

This method is deprecated.

Loaders are managed separately from FragmentController

@NonNull void

This method is deprecated.

Loaders are managed separately from FragmentController

@NonNull void

This method is deprecated.

Loaders are managed separately from FragmentController

@NonNull void
doLoaderStop(@NonNull boolean retain)

This method is deprecated.

Loaders are managed separately from FragmentController

@NonNull void
dumpLoaders(
    @NonNull String prefix,
    @Nullable FileDescriptor fd,
    @NonNull PrintWriter writer,
    @Nullable Array<@NonNull String> args
)

This method is deprecated.

Loaders are managed separately from FragmentController

@NonNull boolean

Execute any pending actions for the Fragments managed by the controller's FragmentManager.

@Nullable Fragment

Returns a fragment with the given identifier.

@NonNull List<@NonNull Fragment>

Returns the list of active fragments.

@NonNull int

Returns the number of active fragments.

@NonNull FragmentManager

Returns a FragmentManager for this controller.

@NonNull LoaderManager

This method is deprecated.

Loaders are managed separately from FragmentController and this now throws an UnsupportedOperationException.

@NonNull void

Marks the fragment state as unsaved.

@Nullable View
onCreateView(
    @Nullable View parent,
    @NonNull String name,
    @NonNull Context context,
    @NonNull AttributeSet attrs
)

Instantiates a Fragment's view.

@NonNull void

This method is deprecated.

Loaders are managed separately from FragmentController

@NonNull void
restoreAllState(
    @Nullable Parcelable state,
    @Nullable List<@NonNull Fragment> nonConfigList
)

This method is deprecated.

Have your FragmentHostCallback implement ViewModelStoreOwner to automatically restore the Fragment's non configuration state and use restoreSaveState to restore the Fragment's save state.

@NonNull void

This method is deprecated.

Have your FragmentHostCallback implement ViewModelStoreOwner to automatically restore the Fragment's non configuration state and use restoreSaveState to restore the Fragment's save state.

@NonNull void

This method is deprecated.

Loaders are managed separately from FragmentController

@NonNull void

This method is deprecated.

Have your FragmentHostCallback implement androidx.savedstate.SavedStateRegistryOwner to automatically restore the saved state via the FragmentManager.

@Nullable SimpleArrayMap<@NonNull String, @NonNull LoaderManager>

This method is deprecated.

Loaders are managed separately from FragmentController

@Nullable FragmentManagerNonConfig

This method is deprecated.

Have your FragmentHostCallback implement ViewModelStoreOwner to automatically retain the Fragment's non configuration state.

@Nullable List<@NonNull Fragment>

This method is deprecated.

Have your FragmentHostCallback implement ViewModelStoreOwner to automatically retain the Fragment's non configuration state.

@Nullable Parcelable

This method is deprecated.

Have your FragmentHostCallback implement androidx.savedstate.SavedStateRegistryOwner to automatically save state via the FragmentManager.

Public methods

attachHost

@NonNull
public void attachHost(@Nullable Fragment parent)

Attaches the host to the FragmentManager for this controller. The host must be attached before the FragmentManager can be used to manage Fragments.

createController

@NonNull
public static FragmentController createController(@NonNull FragmentHostCallback<@NonNull Object> callbacks)

Returns a FragmentController.

dispatchActivityCreated

@NonNull
public void dispatchActivityCreated()

Moves all Fragments managed by the controller's FragmentManager into the activity created state.

Call when Fragments should be informed their host has been created.

See also
Fragment

Fragment#onActivityCreated(Bundle)

dispatchConfigurationChanged

@NonNull
public void dispatchConfigurationChanged(@NonNull Configuration newConfig)

Lets all Fragments managed by the controller's FragmentManager know a configuration change occurred.

Call when there is a configuration change.

See also
onConfigurationChanged

Fragment#onConfigurationChanged(Configuration)

dispatchContextItemSelected

@NonNull
public boolean dispatchContextItemSelected(@NonNull MenuItem item)

Sends a context item selection event to the Fragments managed by the controller's FragmentManager. Once the event has been consumed, no additional handling will be performed.

Call immediately after an options menu item has been selected

Returns
boolean

{@code true} if the context menu selection event was consumed

See also
onContextItemSelected

Fragment#onContextItemSelected(MenuItem)

dispatchCreate

@NonNull
public void dispatchCreate()

Moves all Fragments managed by the controller's FragmentManager into the create state.

Call when Fragments should be created.

See also
Fragment

Fragment#onCreate(Bundle)

dispatchCreateOptionsMenu

@NonNull
public boolean dispatchCreateOptionsMenu(
    @NonNull Menu menu,
    @NonNull MenuInflater inflater
)

Lets all Fragments managed by the controller's FragmentManager know they should create an options menu.

Call when the Fragment should create an options menu.

Returns
boolean

{@code true} if the options menu contains items to display

See also
onCreateOptionsMenu

Fragment#onCreateOptionsMenu(Menu, MenuInflater)

dispatchDestroy

@NonNull
public void dispatchDestroy()

Moves Fragments managed by the controller's FragmentManager into the destroy state.

If the androidx.fragment.app.FragmentHostCallback is an instance of ViewModelStoreOwner, then retained Fragments and any other non configuration state such as any androidx.lifecycle.ViewModel attached to Fragments will only be destroyed if clear is called prior to this method.

Otherwise, the FragmentManager will look to see if the host's Context is an Activity and if isChangingConfigurations returns true. In only that case will non configuration state be retained.

Call when Fragments should be destroyed.

See also
onDestroy

Fragment#onDestroy()

dispatchDestroyView

@NonNull
public void dispatchDestroyView()

Move