FragmentManager

Static library support version of the framework's FragmentManager.
Used to write apps that run on platforms prior to Android 3.0. When running
on Android 3.0 or above, this implementation is still used; it does not try
to switch to the framework's implementation. See the framework FragmentManager
documentation for a class overview.

Constants

Flag for popBackStack(String, int)
and popBackStack(int, int): If set, and the name or ID of
a back stack entry has been supplied, then all matching entries will
be consumed until one that doesn't match is found or the bottom of
the stack is reached.

Constants

POP_BACK_STACK_INCLUSIVE

public static final int POP_BACK_STACK_INCLUSIVE

Flag for popBackStack(String, int)
and popBackStack(int, int): If set, and the name or ID of
a back stack entry has been supplied, then all matching entries will
be consumed until one that doesn't match is found or the bottom of
the stack is reached. Otherwise, all entries up to but not including that entry
will be removed.

executePendingTransactions

public boolean executePendingTransactions ()

After a FragmentTransaction is committed with
FragmentTransaction.commit(), it
is scheduled to be executed asynchronously on the process's main thread.
If you want to immediately executing any such pending operations, you
can call this function (only from the main thread) to do so. Note that
all callbacks and other related behavior will be done from within this
call, so be careful about where this is called from.

If you are committing a single transaction that does not modify the
fragment back stack, strongly consider using
FragmentTransaction.commitNow() instead. This can help avoid
unwanted side effects when other code in your app has pending committed
transactions that expect different timing.

findFragmentById

Finds a fragment that was identified by the given id either when inflated
from XML or as the container ID when added in a transaction. This first
searches through fragments that are currently added to the manager's
activity; if no such fragment is found, then all fragments currently
on the back stack associated with this ID are searched.

findFragmentByTag

Finds a fragment that was identified by the given tag either when inflated
from XML or as supplied when added in a transaction. This first
searches through fragments that are currently added to the manager's
activity; if no such fragment is found, then all fragments currently
on the back stack are searched.

getFragments

Get a list of all fragments that are currently added to the FragmentManager.
This may include those that are hidden as well as those that are shown.
This will not include any fragments only in the back stack, or fragments that
are detached or removed.

The order of the fragments in the list is the order in which they were
added or attached.

true if this FragmentManager's state has already been saved by its host

popBackStack

public void popBackStack ()

Pop the top state off the back stack. This function is asynchronous -- it enqueues the
request to pop, but the action will not be performed until the application
returns to its event loop.

popBackStack

public void popBackStack (int id,
int flags)

Pop all back stack states up to the one with the given identifier.
This function is asynchronous -- it enqueues the
request to pop, but the action will not be performed until the application
returns to its event loop.

popBackStack

public void popBackStack (String name,
int flags)

Pop the last fragment transition from the manager's fragment
back stack.
This function is asynchronous -- it enqueues the
request to pop, but the action will not be performed until the application
returns to its event loop.

Parameters

name

String: If non-null, this is the name of a previous back state
to look for; if found, all states up to that state will be popped. The
POP_BACK_STACK_INCLUSIVE flag can be used to control whether
the named state itself is popped. If null, only the top state is popped.

registerFragmentLifecycleCallbacks

Registers a FragmentManager.FragmentLifecycleCallbacks to listen to fragment lifecycle events
happening in this FragmentManager. All registered callbacks will be automatically
unregistered when this FragmentManager is destroyed.

Parameters

cb

FragmentManager.FragmentLifecycleCallbacks: Callbacks to register

recursive

boolean: true to automatically register this callback for all child FragmentManagers

saveFragmentInstanceState

Save the current instance state of the given Fragment. This can be
used later when creating a new instance of the Fragment and adding
it to the fragment manager, to have it create itself to match the
current state returned here. Note that there are limits on how
this can be used:

The Fragment must currently be attached to the FragmentManager.

A new Fragment created using this saved state must be the same class
type as the Fragment it was created from.

The saved state can not contain dependencies on other fragments --
that is it can't use putFragment(Bundle, String, Fragment) to
store a fragment reference because that reference may not be valid when
this saved state is later used. Likewise the Fragment's target and
result code are not included in this state.

toString

unregisterFragmentLifecycleCallbacks

Unregisters a previously registered FragmentManager.FragmentLifecycleCallbacks. If the callback
was not previously registered this call has no effect. All registered callbacks will be
automatically unregistered when this FragmentManager is destroyed.

Parameters

cb

FragmentManager.FragmentLifecycleCallbacks: Callbacks to unregister

Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.