FileDocCategorySizeDatePackage
FragmentManager.javaAPI DocAndroid 5.1 API86978Thu Mar 12 22:22:56 GMT 2015android.support.v4.app

FragmentManager

public abstract class FragmentManager extends Object
Static library support version of the framework's {@link android.app.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 {@link FragmentManager} documentation for a class overview.

Your activity must derive from {@link FragmentActivity} to use this. From such an activity, you can acquire the {@link FragmentManager} by calling {@link FragmentActivity#getSupportFragmentManager}.

Fields Summary
public static final int
POP_BACK_STACK_INCLUSIVE
Flag for {@link #popBackStack(String, int)} and {@link #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.
Constructors Summary
Methods Summary
public abstract voidaddOnBackStackChangedListener(android.support.v4.app.FragmentManager$OnBackStackChangedListener listener)
Add a new listener for changes to the fragment back stack.

public abstract FragmentTransactionbeginTransaction()
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 {@link FragmentActivity#onSaveInstanceState FragmentActivity.onSaveInstanceState()} (and prior to a following {@link FragmentActivity#onStart FragmentActivity.onStart} or {@link FragmentActivity#onResume 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.

public abstract voiddump(java.lang.String prefix, java.io.FileDescriptor fd, java.io.PrintWriter writer, java.lang.String[] args)
Print the FragmentManager's state into the given stream.

param
prefix Text to print at the front of each line.
param
fd The raw file descriptor that the dump is being sent to.
param
writer A PrintWriter to which the dump is to be set.
param
args Additional arguments to the dump request.

public static voidenableDebugLogging(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.


                                                       
       

                                       
       

                                                                                                                    
          

                                        
          

                                                                                                   
          

                                        
          

                   
       

                             
        

                    
        

                   
        

                                                                          
            

                                                          
          

                                  
       

                                                                                                                                                                                 
        

                               
       

                                                             
              

                                    
         
        FragmentManagerImpl.DEBUG = enabled;
    
public abstract booleanexecutePendingTransactions()
After a {@link FragmentTransaction} is committed with {@link FragmentTransaction#commit 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.

return
Returns true if there were any pending transactions to be executed.

public abstract FragmentfindFragmentById(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.

return
The fragment if found or null otherwise.

public abstract FragmentfindFragmentByTag(java.lang.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.

return
The fragment if found or null otherwise.

public abstract android.support.v4.app.FragmentManager$BackStackEntrygetBackStackEntryAt(int index)
Return the BackStackEntry at index index in the back stack; entries start index 0 being the bottom of the stack.

public abstract intgetBackStackEntryCount()
Return the number of entries currently in the back stack.

public abstract FragmentgetFragment(android.os.Bundle bundle, java.lang.String key)
Retrieve the current Fragment instance for a reference previously placed with {@link #putFragment(Bundle, String, Fragment)}.

param
bundle The bundle from which to retrieve the fragment reference.
param
key The name of the entry in the bundle.
return
Returns the current Fragment instance that is associated with the given reference.

public abstract java.util.ListgetFragments()
Get a list of all fragments that have been added to the fragment manager.

return
The list of all fragments or null if none.
hide

public abstract booleanisDestroyed()
Returns true if the final {@link android.app.Activity#onDestroy() Activity.onDestroy()} call has been made on the FragmentManager's Activity, so this instance is now dead.

public FragmentTransactionopenTransaction()

hide
-- remove once prebuilts are in.

        return beginTransaction();
    
public abstract voidpopBackStack(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.

param
id Identifier of the stated to be popped. If no identifier exists, false is returned. The identifier is the number returned by {@link FragmentTransaction#commit() FragmentTransaction.commit()}. The {@link #POP_BACK_STACK_INCLUSIVE} flag can be used to control whether the named state itself is popped.
param
flags Either 0 or {@link #POP_BACK_STACK_INCLUSIVE}.

public abstract voidpopBackStack()
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.

public abstract voidpopBackStack(java.lang.String name, int flags)
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.

param
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 {@link #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.
param
flags Either 0 or {@link #POP_BACK_STACK_INCLUSIVE}.

public abstract booleanpopBackStackImmediate(int id, int flags)
Like {@link #popBackStack(int, int)}, but performs the operation immediately inside of the call. This is like calling {@link #executePendingTransactions()} afterwards.

return
Returns true if there was something popped, else false.

public abstract booleanpopBackStackImmediate()
Like {@link #popBackStack()}, but performs the operation immediately inside of the call. This is like calling {@link #executePendingTransactions()} afterwards.

return
Returns true if there was something popped, else false.

public abstract booleanpopBackStackImmediate(java.lang.String name, int flags)
Like {@link #popBackStack(String, int)}, but performs the operation immediately inside of the call. This is like calling {@link #executePendingTransactions()} afterwards.

return
Returns true if there was something popped, else false.

public abstract voidputFragment(android.os.Bundle bundle, java.lang.String key, Fragment fragment)
Put a reference to a fragment in a Bundle. This Bundle can be persisted as saved state, and when later restoring {@link #getFragment(Bundle, String)} will return the current instance of the same fragment.

param
bundle The bundle in which to put the fragment reference.
param
key The name of the entry in the bundle.
param
fragment The Fragment whose reference is to be stored.

public abstract voidremoveOnBackStackChangedListener(android.support.v4.app.FragmentManager$OnBackStackChangedListener listener)
Remove a listener that was previously added with {@link #addOnBackStackChangedListener(OnBackStackChangedListener)}.

public abstract Fragment.SavedStatesaveFragmentInstanceState(Fragment f)
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 {@link #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.

param
f The Fragment whose state is to be saved.
return
The generated state. This will be null if there was no interesting state created by the fragment.