belongs to Maven artifact com.android.support:support-fragment:28.0.0-alpha1
FragmentManager
public
abstract
class
FragmentManager
extends Object
java.lang.Object | |
↳ | android.support.v4.app.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.
Your activity must derive from FragmentActivity
to use this. From such an activity,
you can acquire the FragmentManager
by calling
getSupportFragmentManager()
.
Summary
Nested classes | |
---|---|
interface |
FragmentManager.BackStackEntry
Representation of an entry on the fragment back stack, as created
with |
class |
FragmentManager.FragmentLifecycleCallbacks
Callback interface for listening to fragment state changes that happen within a given FragmentManager. |
interface |
FragmentManager.OnBackStackChangedListener
Interface to watch for changes to the back stack. |
Constants | |
---|---|
int |
POP_BACK_STACK_INCLUSIVE
Flag for |
Public constructors | |
---|---|
FragmentManager()
|
Public methods | |
---|---|
abstract
void
|
addOnBackStackChangedListener(FragmentManager.OnBackStackChangedListener listener)
Add a new listener for changes to the fragment back stack. |
abstract
FragmentTransaction
|
beginTransaction()
Start a series of edit operations on the Fragments associated with this FragmentManager. |
abstract
void
|
dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)
Print the FragmentManager's state into the given stream. |
static
void
|
enableDebugLogging(boolean enabled)
Control whether the framework's internal fragment manager debugging logs are turned on. |
abstract
boolean
|
executePendingTransactions()
After a |
abstract
Fragment
|
findFragmentById(int id)
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. |
abstract
Fragment
|
findFragmentByTag(String tag)
Finds a fragment that was identified by the given tag either when inflated from XML or as supplied when added in a transaction. |
abstract
FragmentManager.BackStackEntry
|
getBackStackEntryAt(int index)
Return the BackStackEntry at index index in the back stack; entries start index 0 being the bottom of the stack. |
abstract
int
|
getBackStackEntryCount()
Return the number of entries currently in the back stack. |
abstract
Fragment
|
getFragment(Bundle bundle, String key)
Retrieve the current Fragment instance for a reference previously
placed with |
abstract
List<Fragment>
|
getFragments()
Get a list of all fragments that are currently added to the FragmentManager. |
abstract
Fragment
|
getPrimaryNavigationFragment()
Return the currently active primary navigation fragment for this FragmentManager. |
abstract
boolean
|
isDestroyed()
Returns true if the final |
abstract
boolean
|
isStateSaved()
Returns |
abstract
void
|
popBackStack()
Pop the top state off the back stack. |
abstract
void
|
popBackStack(int id, int flags)
Pop all back stack states up to the one with the given identifier. |
abstract
void
|
popBackStack(String name, int flags)
Pop the last fragment transition from the manager's fragment back stack. |
abstract
boolean
|
popBackStackImmediate()
Like |
abstract
boolean
|
popBackStackImmediate(int id, int flags)
Like |
abstract
boolean
|
popBackStackImmediate(String name, int flags)
Like |
abstract
void
|
putFragment(Bundle bundle, String key, Fragment fragment)
Put a reference to a fragment in a Bundle. |
abstract
void
|
registerFragmentLifecycleCallbacks(FragmentManager.FragmentLifecycleCallbacks cb, boolean recursive)
Registers a |
abstract
void
|
removeOnBackStackChangedListener(FragmentManager.OnBackStackChangedListener listener)
Remove a listener that was previously added with
|
abstract
Fragment.SavedState
|
saveFragmentInstanceState(Fragment f)
Save the current instance state of the given Fragment. |
abstract
void
|
unregisterFragmentLifecycleCallbacks(FragmentManager.FragmentLifecycleCallbacks cb)
Unregisters a previously registered |
Inherited methods | |
---|---|
![]()
java.lang.Object
|
Constants
POP_BACK_STACK_INCLUSIVE
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.
Constant Value: 1 (0x00000001)
Public constructors
Public methods
addOnBackStackChangedListener
void addOnBackStackChangedListener (FragmentManager.OnBackStackChangedListener listener)
Add a new listener for changes to the fragment back stack.
Parameters | |
---|---|
listener |
FragmentManager.OnBackStackChangedListener |
beginTransaction
FragmentTransaction beginTransaction ()
Start a series of edit operations on the Fragments associated with this FragmentManager.
Note: A fragment transaction can only be created/committed prior
to an activity saving its state. If you try to commit a transaction
after FragmentActivity.onSaveInstanceState()
(and prior to a following FragmentActivity.onStart
or FragmentActivity.onResume()
, you will get an error.
This is because the framework takes care of saving your current fragments
in the state, and if changes are made after the state is saved then they
will be lost.
Returns | |
---|---|
FragmentTransaction |
dump
void dump (String prefix, FileDescriptor fd, PrintWriter writer, String[] args)
Print the FragmentManager's state into the given stream.
Parameters | |
---|---|
prefix |
String : Text to print at the front of each line. |
fd |
FileDescriptor : The raw file descriptor that the dump is being sent to. |
writer |
PrintWriter : A PrintWriter to which the dump is to be set. |
args |
String : Additional arguments to the dump request.
|
enableDebugLogging
void enableDebugLogging (boolean enabled)
Control whether the framework's internal fragment manager debugging logs are turned on. If enabled, you will see output in logcat as the framework performs fragment operations.
Parameters | |
---|---|
enabled |
boolean |
executePendingTransactions
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
commitNow()
instead. This can help avoid
unwanted side effects when other code in your app has pending committed
transactions that expect different timing.
This also forces the start of any postponed Transactions where
postponeEnterTransition()
has been called.
Returns | |
---|---|
boolean |
Returns true if there were any pending transactions to be executed. |
findFragmentById
Fragment findFragmentById (int id)
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.
Parameters | |
---|---|
id |
int |
Returns | |
---|---|
Fragment |
The fragment if found or null otherwise. |
findFragmentByTag
Fragment findFragmentByTag (String tag)
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.
Parameters | |
---|---|
tag |
String |
Returns | |
---|---|
Fragment |
The fragment if found or null otherwise. |
getBackStackEntryAt
FragmentManager.BackStackEntry getBackStackEntryAt (int index)
Return the BackStackEntry at index index in the back stack; entries start index 0 being the bottom of the stack.
Parameters | |
---|---|
index |
int |
Returns | |
---|---|
FragmentManager.BackStackEntry |
getBackStackEntryCount
int getBackStackEntryCount ()
Return the number of entries currently in the back stack.
Returns | |
---|---|
|