public class FragmentController extends Object
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.
Modifier and Type | Method and Description |
---|---|
void |
attachHost(Fragment parent)
Attaches the host to the FragmentManager for this controller.
|
static FragmentController |
createController(FragmentHostCallback<?> callbacks)
Returns a
FragmentController . |
void |
dispatchActivityCreated()
Moves all Fragments managed by the controller's FragmentManager
into the activity created state.
|
void |
dispatchConfigurationChanged(Configuration newConfig)
Lets all Fragments managed by the controller's FragmentManager
know a configuration change occurred.
|
boolean |
dispatchContextItemSelected(MenuItem item)
Sends a context item selection event to the Fragments managed by the
controller's FragmentManager.
|
void |
dispatchCreate()
Moves all Fragments managed by the controller's FragmentManager
into the create state.
|
boolean |
dispatchCreateOptionsMenu(Menu menu,
MenuInflater inflater)
Lets all Fragments managed by the controller's FragmentManager
know they should create an options menu.
|
void |
dispatchDestroy()
Moves all Fragments managed by the controller's FragmentManager
into the destroy state.
|
void |
dispatchDestroyView()
Moves all Fragments managed by the controller's FragmentManager
into the destroy view state.
|
void |
dispatchLowMemory()
Lets all Fragments managed by the controller's FragmentManager
know the device is in a low memory condition.
|
void |
dispatchMultiWindowModeChanged(boolean isInMultiWindowMode)
Lets all Fragments managed by the controller's FragmentManager know the multi-window mode of
the activity changed.
|
boolean |
dispatchOptionsItemSelected(MenuItem item)
Sends an option item selection event to the Fragments managed by the
controller's FragmentManager.
|
void |
dispatchOptionsMenuClosed(Menu menu)
Lets all Fragments managed by the controller's FragmentManager
know their options menu has closed.
|
void |
dispatchPause()
Moves all Fragments managed by the controller's FragmentManager
into the pause state.
|
void |
dispatchPictureInPictureModeChanged(boolean isInPictureInPictureMode)
Lets all Fragments managed by the controller's FragmentManager know the picture-in-picture
mode of the activity changed.
|
boolean |
dispatchPrepareOptionsMenu(Menu menu)
Lets all Fragments managed by the controller's FragmentManager
know they should prepare their options menu for display.
|
void |
dispatchResume()
Moves all Fragments managed by the controller's FragmentManager
into the resume state.
|
void |
dispatchStart()
Moves all Fragments managed by the controller's FragmentManager
into the start state.
|
void |
dispatchStop()
Moves all Fragments managed by the controller's FragmentManager
into the stop state.
|
void |
dispatchTrimMemory(int level)
Lets all Fragments managed by the controller's FragmentManager
know they should trim their memory usage.
|
void |
doLoaderDestroy()
Destroys the loaders and, if their state is not being retained, removes them.
|
void |
doLoaderStart()
Starts the loaders.
|
void |
doLoaderStop(boolean retain)
Stops the loaders, optionally retaining their state.
|
void |
dumpLoaders(String prefix,
FileDescriptor fd,
PrintWriter writer,
String[] args)
Dumps the current state of the loaders.
|
boolean |
execPendingActions()
Execute any pending actions for the Fragments managed by the
controller's FragmentManager.
|
Fragment |
findFragmentByWho(String who)
Returns a fragment with the given identifier.
|
FragmentManager |
getFragmentManager()
Returns a
FragmentManager for this controller. |
LoaderManager |
getLoaderManager()
Returns a
LoaderManager . |
void |
noteStateNotSaved()
Marks the fragment state as unsaved.
|
View |
onCreateView(View parent,
String name,
Context context,
AttributeSet attrs)
Instantiates a Fragment's view.
|
void |
reportLoaderStart()
Lets the loaders know the host is ready to receive notifications.
|
void |
restoreAllState(Parcelable state,
FragmentManagerNonConfig nonConfig)
Restores the saved state for all Fragments.
|
void |
restoreAllState(Parcelable state,
List<Fragment> nonConfigList)
Deprecated.
|
void |
restoreLoaderNonConfig(ArrayMap<String,LoaderManager> loaderManagers)
Restores the saved state for all LoaderManagers.
|
ArrayMap<String,LoaderManager> |
retainLoaderNonConfig()
Returns a list of LoaderManagers that have opted to retain their instance across
configuration changes.
|
FragmentManagerNonConfig |
retainNestedNonConfig()
Returns a nested tree of Fragments that have opted to retain their instance across
configuration changes.
|
List<Fragment> |
retainNonConfig()
Deprecated.
use
retainNestedNonConfig() to also track retained
nested child fragments |
Parcelable |
saveAllState()
Saves the state for all Fragments.
|
public static final FragmentController createController(FragmentHostCallback<?> callbacks)
FragmentController
.public FragmentManager getFragmentManager()
FragmentManager
for this controller.public LoaderManager getLoaderManager()
LoaderManager
.public Fragment findFragmentByWho(String who)
public void attachHost(Fragment parent)
public View onCreateView(View parent, String name, Context context, AttributeSet attrs)
parent
- The parent that the created view will be placed
in; note that this may be null.name
- Tag name to be inflated.context
- The context the view is being created in.attrs
- Inflation attributes as specified in XML file.public void noteStateNotSaved()
public Parcelable saveAllState()
public void restoreAllState(Parcelable state, List<Fragment> nonConfigList)
restoreAllState(Parcelable, FragmentManagerNonConfig)
retainNonConfig()
public void restoreAllState(Parcelable state, FragmentManagerNonConfig nonConfig)
retainNestedNonConfig()
public List<Fragment> retainNonConfig()
retainNestedNonConfig()
to also track retained
nested child fragmentspublic FragmentManagerNonConfig retainNestedNonConfig()
public void dispatchCreate()
Call when Fragments should be created.
Fragment.onCreate(Bundle)
public void dispatchActivityCreated()
Call when Fragments should be informed their host has been created.
Fragment.onActivityCreated(Bundle)
public void dispatchStart()
Call when Fragments should be started.
Fragment.onStart()
public void dispatchResume()
Call when Fragments should be resumed.
Fragment.onResume()
public void dispatchPause()
Call when Fragments should be paused.
Fragment.onPause()
public void dispatchStop()
Call when Fragments should be stopped.
Fragment.onStop()
public void dispatchDestroyView()
Call when the Fragment's views should be destroyed.
Fragment.onDestroyView()
public void dispatchDestroy()
Call when Fragments should be destroyed.
Fragment.onDestroy()
public void dispatchMultiWindowModeChanged(boolean isInMultiWindowMode)
Call when the multi-window mode of the activity changed.
public void dispatchPictureInPictureModeChanged(boolean isInPictureInPictureMode)
Call when the picture-in-picture mode of the activity changed.
public void dispatchConfigurationChanged(Configuration newConfig)
Call when there is a configuration change.
public void dispatchLowMemory()
Call when the device is low on memory and Fragment's should trim their memory usage.
Fragment.onLowMemory()
public void dispatchTrimMemory(int level)
Call when the Fragment can release allocated memory [such as if the Fragment is in the background].
Fragment.onTrimMemory(int)
public boolean dispatchCreateOptionsMenu(Menu menu, MenuInflater inflater)
Call when the Fragment should create an options menu.
true
if the options menu contains items to displayFragment.onCreateOptionsMenu(Menu, MenuInflater)
public boolean dispatchPrepareOptionsMenu(Menu menu)
Call immediately before displaying the Fragment's options menu.
true
if the options menu contains items to displayFragment.onPrepareOptionsMenu(Menu)
public boolean dispatchOptionsItemSelected(MenuItem item)
Call immediately after an options menu item has been selected
true
if the options menu selection event was consumedFragment.onOptionsItemSelected(MenuItem)
public boolean dispatchContextItemSelected(MenuItem item)
Call immediately after an options menu item has been selected
true
if the context menu selection event was consumedFragment.onContextItemSelected(MenuItem)
public void dispatchOptionsMenuClosed(Menu menu)
Call immediately after closing the Fragment's options menu.
Fragment.onOptionsMenuClosed(Menu)
public boolean execPendingActions()
Call when queued actions can be performed [eg when the Fragment moves into a start or resume state].
true
if queued actions were performedpublic void doLoaderStart()
public void doLoaderStop(boolean retain)
retain
- When true
, the loaders aren't stopped, but, their instances
are retained in a started statepublic void doLoaderDestroy()
public void reportLoaderStart()
public ArrayMap<String,LoaderManager> retainLoaderNonConfig()
public void restoreLoaderNonConfig(ArrayMap<String,LoaderManager> loaderManagers)
retainLoaderNonConfig()
public void dumpLoaders(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)