Register now for Android Dev Summit 2019!

FragmentController

open class FragmentController
kotlin.Any
   ↳ androidx.fragment.app.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

open Unit
attachHost(@Nullable parent: Fragment?)

Attaches the host to the FragmentManager for this controller.

open static FragmentController
createController(@NonNull callbacks: FragmentHostCallback<*>)

Returns a FragmentController.

open Unit

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

open Unit

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

open Boolean

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

open Unit

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

open Boolean
dispatchCreateOptionsMenu(@NonNull menu: Menu, @NonNull inflater: MenuInflater)

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

open Unit

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

open Unit

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

open Unit

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

open Unit

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

open Boolean

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

open Unit

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

open Unit

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

open Unit
dispatchPictureInPictureModeChanged(isInPictureInPictureMode: Boolean)

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

open Boolean

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

open Unit

open Unit

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

open Unit

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

open Unit

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

open Unit

Destroys the loaders and, if their state is not being retained, removes them.

open Unit

Retains the state of each of the loaders.

open Unit

Starts the loaders.

open Unit

Stops the loaders, optionally retaining their state.

open Unit
dumpLoaders(@NonNull prefix: String, @Nullable fd: FileDescriptor?, @NonNull writer: PrintWriter, @Nullable args: Array<String!>?)

Dumps the current state of the loaders.

open Boolean

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

open Fragment?
findFragmentByWho(@NonNull who: String)

Returns a fragment with the given identifier.

open MutableList<Fragment!>

Returns the list of active fragments.

open Int

Returns the number of active fragments.

open FragmentManager

Returns a FragmentManager for this controller.

open LoaderManager!

Returns a LoaderManager.

open Unit

Marks the fragment state as unsaved.

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

Instantiates a Fragment's view.

open Unit

Lets the loaders know the host is ready to receive notifications.

open Unit
restoreAllState(@Nullable state: Parcelable?, @Nullable nonConfigList: MutableList<Fragment!>?)

Restores the saved state for all Fragments.

open Unit
restoreAllState(@Nullable state: Parcelable?, @Nullable nonConfig: FragmentManagerNonConfig?)

Restores the saved state for all Fragments.

open Unit

Restores the saved state for all LoaderManagers.

open Unit
restoreSaveState(@Nullable state: Parcelable?)

Restores the saved state for all Fragments.

open SimpleArrayMap<String!, LoaderManager!>?

Returns a list of LoaderManagers that have opted to retain their instance across configuration changes.

open FragmentManagerNonConfig?

Returns a nested tree of Fragments that have opted to retain their instance across configuration changes.

open MutableList<Fragment!>?

Returns a list of Fragments that have opted to retain their instance across configuration changes.

open Parcelable?

Saves the state for all Fragments.

Public methods

attachHost

open fun attachHost(@Nullable parent: Fragment?): Unit

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 open static fun createController(@NonNull callbacks: FragmentHostCallback<*>): FragmentController

Returns a FragmentController.

dispatchActivityCreated

open fun dispatchActivityCreated(): Unit

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#onActivityCreated(Bundle)

dispatchConfigurationChanged

open fun dispatchConfigurationChanged(@NonNull newConfig: Configuration): Unit

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

Call when there is a configuration change.

dispatchContextItemSelected

open fun dispatchContextItemSelected(@NonNull item: MenuItem): Boolean

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

Return
Boolean: true if the context menu selection event was consumed

dispatchCreate

open fun dispatchCreate(): Unit

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

Call when Fragments should be created.

See Also

  • Fragment#onCreate(Bundle)

dispatchCreateOptionsMenu

open fun dispatchCreateOptionsMenu(@NonNull menu: Menu, @NonNull inflater: MenuInflater): Boolean

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.

Return
Boolean: true if the options menu contains items to display

dispatchDestroy

open fun dispatchDestroy(): Unit

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 androidx.lifecycle.ViewModelStore#clear() is called prior to this method.

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

Call when Fragments should be destroyed.

dispatchDestroyView

open fun dispatchDestroyView(): Unit

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

Call when the Fragment's views should be destroyed.

dispatchLowMemory

open fun dispatchLowMemory(): Unit

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

Call when the device is low on memory and Fragment's should trim their memory usage.

dispatchMultiWindowModeChanged

open fun dispatchMultiWindowModeChanged(isInMultiWindowMode: Boolean): Unit

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

Call when the multi-window mode of the activity changed.

dispatchOptionsItemSelected

open fun dispatchOptionsItemSelected(@NonNull item: MenuItem): Boolean

Sends an option 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

Return
Boolean: true if the options menu selection event was consumed

dispatchOptionsMenuClosed

open fun dispatchOptionsMenuClosed(@NonNull menu: Menu): Unit

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

Call immediately after closing the Fragment's options menu.

dispatchPause

open fun dispatchPause(): Unit

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

Call when Fragments should be paused.

dispatchPictureInPictureModeChanged

open fun dispatchPictureInPictureModeChanged(isInPictureInPictureMode: Boolean): Unit

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

Call when the picture-in-picture mode of the activity changed.

dispatchPrepareOptionsMenu

open fun dispatchPrepareOptionsMenu(@NonNull menu: Menu): Boolean

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

Call immediately before displaying the Fragment's options menu.

Return
Boolean: true if the options menu contains items to display

dispatchReallyStop

open fun dispatchReallyStop(): Unit

Deprecated: This functionality has been rolled into dispatchStop().

dispatchResume

open fun dispatchResume(): Unit

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

Call when Fragments should be resumed.

dispatchStart

open fun dispatchStart(): Unit

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

Call when Fragments should be started.

dispatchStop

open fun dispatchStop(): Unit

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

Call when Fragments should be stopped.

doLoaderDestroy

open fun doLoaderDestroy(): Unit

Deprecated: Loaders are managed separately from FragmentController

Destroys the loaders and, if their state is not being retained, removes them.

doLoaderRetain

open fun doLoaderRetain(): Unit

Deprecated: Loaders are managed separately from FragmentController

Retains the state of each of the loaders.

doLoaderStart

open fun doLoaderStart(): Unit

Deprecated: Loaders are managed separately from FragmentController

Starts the loaders.

doLoaderStop

open fun doLoaderStop(retain: Boolean): Unit

Deprecated: Loaders are managed separately from FragmentController

Stops the loaders, optionally retaining their state. This is useful for keeping the loader state across configuration changes.

Parameters
retain Boolean: When true, the loaders aren't stopped, but, their instances are retained in a started state

dumpLoaders

open fun dumpLoaders(@NonNull prefix: String, @Nullable fd: FileDescriptor?, @NonNull writer: PrintWriter, @Nullable args: Array<String!>?): Unit

Deprecated: Loaders are managed separately from FragmentController

Dumps the current state of the loaders.

execPendingActions

open fun execPendingActions(): Boolean

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

Call when queued actions can be performed [eg when the Fragment moves into a start or resume state].

Return
Boolean: true if queued actions were performed

findFragmentByWho

@Nullable open fun findFragmentByWho(@NonNull who: String): Fragment?

Returns a fragment with the given identifier.

getActiveFragments

@NonNull open fun getActiveFragments(actives: MutableList<Fragment!>!): MutableList<Fragment!>

Returns the list of active fragments.

getActiveFragmentsCount

open fun getActiveFragmentsCount(): Int

Returns the number of active fragments.

getSupportFragmentManager

@NonNull open fun getSupportFragmentManager(): FragmentManager

Returns a FragmentManager for this controller.

getSupportLoaderManager

open fun getSupportLoaderManager(): LoaderManager!

Deprecated: Loaders are managed separately from FragmentController and this now throws an UnsupportedOperationException. Use LoaderManager#getInstance to obtain a LoaderManager.

Returns a LoaderManager.

noteStateNotSaved

open fun noteStateNotSaved(): Unit

Marks the fragment state as unsaved. This allows for "state loss" detection.

onCreateView

@Nullable open fun onCreateView(@Nullable parent: View?, @NonNull name: String, @NonNull context: Context, @NonNull attrs: AttributeSet): View?

Instantiates a Fragment's view.

Parameters
parent View?: The parent that the created view will be placed in; note that this may be null.
name View?: Tag name to be inflated.
context View?: The context the view is being created in.
attrs View?: Inflation attributes as specified in XML file.
Return
View?: view the newly created view

reportLoaderStart

open fun reportLoaderStart(): Unit

Deprecated: Loaders are managed separately from FragmentController

Lets the loaders know the host is ready to receive notifications.

restoreAllState

open fun restoreAllState(@Nullable state: Parcelable?, @Nullable nonConfigList: MutableList<Fragment!>?): Unit

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

Restores the saved state for all Fragments. The given Fragment list are Fragment instances retained across configuration changes.

restoreAllState

open fun restoreAllState(@Nullable state: Parcelable?, @Nullable nonConfig: FragmentManagerNonConfig?): Unit

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

Restores the saved state for all Fragments. The given FragmentManagerNonConfig are Fragment instances retained across configuration changes, including nested fragments

restoreLoaderNonConfig

open fun restoreLoaderNonConfig(loaderManagers: SimpleArrayMap<String!, LoaderManager!>!): Unit

Deprecated: Loaders are managed separately from FragmentController

Restores the saved state for all LoaderManagers. The given LoaderManager list are LoaderManager instances retained across configuration changes.

restoreSaveState

open fun restoreSaveState(@Nullable state: Parcelable?): Unit

Restores the saved state for all Fragments.

Parameters
state Parcelable?: the saved state containing the Parcelable returned by saveAllState()

See Also

retainLoaderNonConfig

@Nullable open fun retainLoaderNonConfig(): SimpleArrayMap<String!, LoaderManager!>?

Deprecated: Loaders are managed separately from FragmentController

Returns a list of LoaderManagers that have opted to retain their instance across configuration changes.

retainNestedNonConfig

@Nullable open fun retainNestedNonConfig(): FragmentManagerNonConfig?

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

Returns a nested tree of Fragments that have opted to retain their instance across configuration changes.

retainNonConfig

@Nullable open fun retainNonConfig(): MutableList<Fragment!>?

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

Returns a list of Fragments that have opted to retain their instance across configuration changes.

saveAllState

@Nullable open fun saveAllState(): Parcelable?

Saves the state for all Fragments.