package android.support.v4.app;
Representation of an entry on the fragment back stack, as created
with
FragmentTransaction.addToBackStack()
. Entries can later be
retrieved with
FragmentManager.getBackStackEntry()
.
Note that you should never hold on to a BackStackEntry object;
the identifier as returned by getId()
is the only thing that
will be persisted across activity instances.
Return the unique identifier for the entry. This is the only
representation of the entry that will persist across activity
instances.
Get the name that was supplied to
FragmentTransaction.addToBackStack(String)
when creating this entry.
Return the full bread crumb title resource identifier for the entry,
or 0 if it does not have one.
Return the short bread crumb title resource identifier for the entry,
or 0 if it does not have one.
Return the full bread crumb title for the entry, or null if it
does not have one.
Return the short bread crumb title for the entry, or null if it
does not have one.
Interface to watch for changes to the back stack.
Called whenever the contents of the back stack change.
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.
- Hide:
- -- remove once prebuilts are in.
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.
- Returns:
- Returns true if there were any pending transactions to be
executed.
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.
- Returns:
- The fragment if found or null otherwise.
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.
- Returns:
- The fragment if found or null otherwise.
Flag for
popBackStack(java.lang.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.
Pop the top state off the back stack. Returns true if there was one
to pop, else false. 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.
Pop the last fragment transition from the manager's fragment
back stack. If there is nothing to pop, false is returned.
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
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.flags
Either 0 or POP_BACK_STACK_INCLUSIVE
.
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.
- Parameters:
id
Identifier of the stated to be popped. If no identifier exists,
false is returned.
The identifier is the number returned by
FragmentTransaction.commit()
. The
POP_BACK_STACK_INCLUSIVE
flag can be used to control whether
the named state itself is popped.flags
Either 0 or POP_BACK_STACK_INCLUSIVE
.
Return the number of entries currently in the back stack.
Return the BackStackEntry at index
index in the back stack;
entries start index 0 being the bottom of the stack.
Add a new listener for changes to the fragment back stack.
Put a reference to a fragment in a Bundle. This Bundle can be
persisted as saved state, and when later restoring
getFragment(android.os.Bundle,java.lang.String)
will return the current
instance of the same fragment.
- Parameters:
bundle
The bundle in which to put the fragment reference.key
The name of the entry in the bundle.fragment
The Fragment whose reference is to be stored.
Get a list of all fragments that have been added to the fragment manager.
- Returns:
- The list of all fragments or null if none.
- Hide:
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(android.os.Bundle,java.lang.String,android.support.v4.app.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.
- Parameters:
f
The Fragment whose state is to be saved.- Returns:
- The generated state. This will be null if there was no
interesting state created by the fragment.
Returns true if the final
Activity.onDestroy()
call has been made on the FragmentManager's Activity, so this instance is now dead.
Print the FragmentManager's state into the given stream.
- Parameters:
prefix
Text to print at the front of each line.fd
The raw file descriptor that the dump is being sent to.writer
A PrintWriter to which the dump is to be set.args
Additional arguments to the dump request.
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.
Callbacks from FragmentManagerImpl to its container.
Container for fragments associated with an activity.
static boolean DEBUG = false;
Log.e(TAG, "Activity state:");
Log.e(TAG, "Failed dumping state", e);
Log.e(TAG, "Failed dumping state", e);
if (fragment.mIndex < 0) {
+ " is not currently in the FragmentManager"));
bundle.putInt(key, fragment.mIndex);
int index = bundle.getInt(key, -1);
+ key + ": index " + index));
+ key + ": index " + index));
if (fragment.mIndex < 0) {
+ " is not currently in the FragmentManager"));
sb.append("FragmentManager{");
String innerPrefix = prefix + " ";
writer.print(prefix); writer.print("Active Fragments in ");
for (int i=0; i<N; i++) {
f.dump(innerPrefix, fd, writer, args);
for (int i=0; i<N; i++) {
writer.print(prefix); writer.println("Fragments Created Menus:");
for (int i=0; i<N; i++) {
for (int i=0; i<N; i++) {
bs.dump(innerPrefix, fd, writer, args);
writer.print(prefix); writer.println("Back Stack Indices:");
for (int i=0; i<N; i++) {
writer.print(prefix); writer.print("mAvailBackStackIndices: ");
for (int i=0; i<N; i++) {
writer.print(prefix); writer.println("FragmentManager misc state:");
writer.print(prefix); writer.print(" mNeedMenuInvalidate=");
writer.print(prefix); writer.print(" mNoTransactionsBecause=");
writer.print(prefix); writer.print(" mAvailIndices: ");
float endScale, float startAlpha, float endAlpha) {
if (fragment.mNextAnim != 0) {
if (transitionStyle == 0) {
if (f.mRemoving && newState > f.mState) {
if (f.mState < newState) {
if (f.mFromLayout && !f.mInLayout) {
if (f.mAnimatingAway != null) {
if (DEBUG) Log.v(TAG, "moveto CREATED: " + f);
if (f.mSavedFragmentState != null) {
f.mTargetRequestCode = f.mSavedFragmentState.getInt(
f.mUserVisibleHint = f.mSavedFragmentState.getBoolean(
if (!f.mUserVisibleHint) {
f.mFragmentManager = mParent != null
+ " did not call through to super.onAttach()");
if (f.mParentFragment == null) {
f.mSavedFragmentState), null, f.mSavedFragmentState);
f.mView = NoSaveStateFrameLayout.wrap(f.mView);
if (DEBUG) Log.v(TAG, "moveto ACTIVITY_CREATED: " + f);
if (f.mContainerId != 0) {
if (container == null && !f.mRestored) {
"No view found for id 0x"
+ ") for fragment " + f));
f.mContainer = container;
f.mSavedFragmentState), container, f.mSavedFragmentState);
f.mView = NoSaveStateFrameLayout.wrap(f.mView);
f.mSavedFragmentState = null;
if (DEBUG) Log.v(TAG, "moveto STARTED: " + f);
if (DEBUG) Log.v(TAG, "moveto RESUMED: " + f);
f.mSavedFragmentState = null;
f.mSavedViewState = null;
} else if (f.mState > newState) {
if (DEBUG) Log.v(TAG, "movefrom RESUMED: " + f);
if (DEBUG) Log.v(TAG, "movefrom STARTED: " + f);
if (DEBUG) Log.v(TAG, "movefrom STOPPED: " + f);
if (DEBUG) Log.v(TAG, "movefrom ACTIVITY_CREATED: " + f);
if (f.mView != null && f.mContainer != null) {
f.mAnimatingAway = f.mView;
f.mStateAfterAnimating = newState;
if (fragment.mAnimatingAway != null) {
fragment.mAnimatingAway = null;
if (f.mAnimatingAway != null) {
View v = f.mAnimatingAway;
if (f.mAnimatingAway != null) {
f.mStateAfterAnimating = newState;
if (DEBUG) Log.v(TAG, "movefrom CREATED: " + f);
+ " did not call through to super.onDetach()");
f.mParentFragment = null;
f.mFragmentManager = null;
f.mChildFragmentManager = null;
void moveToState(int newState, int transit, int transitStyle, boolean always) {
boolean loadersRunning = false;
moveToState(f, newState, transit, transitStyle, false);
if (f.mLoaderManager != null) {
if (DEBUG) Log.v(TAG, "Allocated fragment index " + f);
if (DEBUG) Log.v(TAG, "Freeing fragment index " + f);