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 TypeMethodDescriptionvoid
attachHost
(Fragment parent) Attaches the host to the FragmentManager for this controller.static FragmentController
createController
(FragmentHostCallback<?> callbacks) Returns aFragmentController
.void
Moves all Fragments managed by the controller's FragmentManager into the activity created state.void
Moves all Fragments managed by the controller's FragmentManager into the create state.void
Moves Fragments managed by the controller's FragmentManager into the destroy state.void
Moves all Fragments managed by the controller's FragmentManager into the destroy view state.void
Moves all Fragments managed by the controller's FragmentManager into the pause state.void
Moves all Fragments managed by the controller's FragmentManager into the resume state.void
Moves all Fragments managed by the controller's FragmentManager into the start state.void
Moves all Fragments managed by the controller's FragmentManager into the stop state.boolean
Execute any pending actions for the Fragments managed by the controller's FragmentManager.findFragmentByWho
(String who) Returns a fragment with the given identifier.int
Returns the number of active fragments.Returns the list of active fragments.Returns aFragmentManager
for this controller.void
Marks the fragment state as unsaved.
-
Method Details
-
createController
@Nonnull public static FragmentController createController(@Nonnull FragmentHostCallback<?> callbacks) Returns aFragmentController
. -
getFragmentManager
Returns aFragmentManager
for 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
FragmentHostCallback
is an instance ofViewModelStoreOwner
, then retained Fragments and any other non configuration state such as anyViewModel
attached 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:
true
if queued actions were performed
-