Class FragmentController
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.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidattachHost(Fragment parent) Attaches the host to the FragmentManager for this controller.static FragmentControllercreateController(FragmentHostCallback<?> callbacks) Returns aFragmentController.voidMoves all Fragments managed by the controller's FragmentManager into the activity created state.voidMoves all Fragments managed by the controller's FragmentManager into the create state.voidMoves Fragments managed by the controller's FragmentManager into the destroy state.voidMoves all Fragments managed by the controller's FragmentManager into the destroy view state.voidMoves all Fragments managed by the controller's FragmentManager into the pause state.voidMoves all Fragments managed by the controller's FragmentManager into the resume state.voidMoves all Fragments managed by the controller's FragmentManager into the start state.voidMoves all Fragments managed by the controller's FragmentManager into the stop state.booleanExecute any pending actions for the Fragments managed by the controller's FragmentManager.findFragmentByWho(String who) Returns a fragment with the given identifier.intReturns the number of active fragments.Returns the list of active fragments.Returns aFragmentManagerfor this controller.voidMarks the fragment state as unsaved.
-
Method Details
-
createController
@Nonnull public static FragmentController createController(@Nonnull FragmentHostCallback<?> callbacks) Returns aFragmentController. -
getFragmentManager
Returns aFragmentManagerfor this controller. -
findFragmentByWho
Returns a fragment with the given identifier. -
getActiveFragmentCount
public int getActiveFragmentCount()Returns the number of active fragments. -
getActiveFragments
Returns the list of active fragments. -
attachHost
Attaches the host to the FragmentManager for this controller. The host must be attached before the FragmentManager can be used to manage Fragments. -
noteStateNotSaved
public void noteStateNotSaved()Marks the fragment state as unsaved. This allows for "state loss" detection. -
dispatchCreate
public void dispatchCreate()Moves all Fragments managed by the controller's FragmentManager into the create state.Call when Fragments should be created.
- See Also:
-
dispatchActivityCreated
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.
-
dispatchStart
public void dispatchStart()Moves all Fragments managed by the controller's FragmentManager into the start state.Call when Fragments should be started.
- See Also:
-
dispatchResume
public void dispatchResume()Moves all Fragments managed by the controller's FragmentManager into the resume state.Call when Fragments should be resumed.
- See Also:
-
dispatchPause
public void dispatchPause()Moves all Fragments managed by the controller's FragmentManager into the pause state.Call when Fragments should be paused.
- See Also:
-
dispatchStop
public void dispatchStop()Moves all Fragments managed by the controller's FragmentManager into the stop state.Call when Fragments should be stopped.
- See Also:
-
dispatchDestroyView
public void dispatchDestroyView()Moves all Fragments managed by the controller's FragmentManager into the destroy view state.Call when the Fragment's views should be destroyed.
- See Also:
-
dispatchDestroy
public void dispatchDestroy()Moves Fragments managed by the controller's FragmentManager into the destroy state.If the
FragmentHostCallbackis an instance ofViewModelStoreOwner, then retained Fragments and any other non configuration state such as anyViewModelattached to Fragments will only be destroyed ifViewModelStore.clear()is called prior to this method.Call when Fragments should be destroyed.
- See Also:
-
execPendingActions
public boolean execPendingActions()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].
- Returns:
trueif queued actions were performed
-