FragmentManager

public abstract class FragmentManager
extends Object implements FragmentResultOwner

java.lang.Object
   ↳ androidx.fragment.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 FragmentActivity.getSupportFragmentManager().

Summary

Nested classes

interface FragmentManager.BackStackEntry

Representation of an entry on the fragment back stack, as created with FragmentTransaction.addToBackStack()

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 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.

Public constructors

FragmentManager()

Public methods

void addFragmentOnAttachListener(FragmentOnAttachListener listener)

Add a FragmentOnAttachListener that should receive a call to FragmentOnAttachListener.onAttachFragment(FragmentManager, Fragment) when a new Fragment is attached to this FragmentManager.

void addOnBackStackChangedListener(FragmentManager.OnBackStackChangedListener listener)

Add a new listener for changes to the fragment back stack.

FragmentTransaction beginTransaction()

Start a series of edit operations on the Fragments associated with this FragmentManager.

final void clearFragmentResult(String requestKey)

Clears the stored result for the given requestKey.

final void clearFragmentResultListener(String requestKey)

Clears the stored FragmentResultListener for the given requestKey.

void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)

Print the FragmentManager's state into the given stream.

static void enableDebugLogging(boolean enabled)

This method is deprecated. FragmentManager now respects Log.isLoggable(String, int) for debug logging, allowing you to use adb shell setprop log.tag.FragmentManager VERBOSE.

boolean executePendingTransactions()

After a FragmentTransaction is committed with FragmentTransaction.commit(), it is scheduled to be executed asynchronously on the process's main thread.

static <F extends Fragment> F findFragment(View view)

Find a Fragment associated with the given View.

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.

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.

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.

int getBackStackEntryCount()

Return the number of entries currently in the back stack.

Fragment getFragment(Bundle bundle, String key)

Retrieve the current Fragment instance for a reference previously placed with putFragment(Bundle, String, Fragment).

FragmentFactory getFragmentFactory()

Gets the current FragmentFactory used to instantiate new Fragment instances.

List<Fragment> getFragments()

Get a list of all fragments that are currently added to the FragmentManager.

Fragment getPrimaryNavigationFragment()

Return the currently active primary navigation fragment for this FragmentManager.

FragmentStrictMode.Policy getStrictModePolicy()

Returns the current policy for this FragmentManager.

boolean isDestroyed()

Returns true if the final Activity.onDestroy() call has been made on the FragmentManager's Activity, so this instance is now dead.

boolean isStateSaved()

Returns true if the FragmentManager's state has already been saved by its host.

void popBackStack()

Pop the top state off the back stack.

void popBackStack(int id, int flags)

Pop all back stack states up to the one with the given identifier.

void popBackStack(String name, int flags)

Pop the last fragment transition from the manager's fragment back stack.

boolean popBackStackImmediate()

Like popBackStack(), but performs the operation immediately inside of the call.

boolean popBackStackImmediate(int id, int flags)

Like popBackStack(int, int), but performs the operation immediately inside of the call.

boolean popBackStackImmediate(String name, int flags)

Like popBackStack(String, int), but performs the operation immediately inside of the call.

void putFragment(Bundle bundle, String key, Fragment fragment)

Put a reference to a fragment in a Bundle.

void registerFragmentLifecycleCallbacks(FragmentManager.FragmentLifecycleCallbacks cb, boolean recursive)

Registers a FragmentManager.FragmentLifecycleCallbacks to listen to fragment lifecycle events happening in this FragmentManager.

void removeFragmentOnAttachListener(FragmentOnAttachListener listener)

Remove a FragmentOnAttachListener that was previously added via addFragmentOnAttachListener(FragmentOnAttachListener).

void removeOnBackStackChangedListener(FragmentManager.OnBackStackChangedListener listener)

Remove a listener that was previously added with addOnBackStackChangedListener(OnBackStackChangedListener).

void restoreBackStack(String name)

Restores the back stack previously saved via saveBackStack(String).

void saveBackStack(String name)

Save the back stack.

Fragment.SavedState saveFragmentInstanceState(Fragment fragment)

Save the current instance state of the given Fragment.

void setFragmentFactory(FragmentFactory fragmentFactory)

Set a FragmentFactory for this FragmentManager that will be used to create new Fragment instances from this point onward.

final void setFragmentResult(String requestKey, Bundle result)

Sets the given result for the requestKey.

final void setFragmentResultListener(String requestKey, LifecycleOwner lifecycleOwner, FragmentResultListener listener)

Sets the FragmentResultListener for a given requestKey.

void setStrictModePolicy(FragmentStrictMode.Policy policy)

Sets the policy for what actions should be detected, as well as the penalty if such actions occur.

String toString()
void unregisterFragmentLifecycleCallbacks(FragmentManager.FragmentLifecycleCallbacks cb)

Unregisters a previously registered FragmentManager.FragmentLifecycleCallbacks.

Inherited methods

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.

Constant Value: 1 (0x00000001)

Public constructors

FragmentManager

public FragmentManager ()

Public methods

addFragmentOnAttachListener

public void addFragmentOnAttachListener (