# FragmentManager

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentManager.java+class:androidx.fragment.app.FragmentManager) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

*** ** * ** ***

<br />

```
public abstract class FragmentManager implements FragmentResultOwner
```

<br />

*** ** * ** ***

Static library support version of the framework's `https://developer.android.com/reference/android/app/FragmentManager.html`. 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 `https://developer.android.com/reference/androidx/fragment/app/FragmentManager` documentation for a class overview.

Your activity must derive from `https://developer.android.com/reference/androidx/fragment/app/FragmentActivity` to use this. From such an activity, you can acquire the `https://developer.android.com/reference/androidx/fragment/app/FragmentManager` by calling `https://developer.android.com/reference/androidx/fragment/app/FragmentActivity#getSupportFragmentManager()`.

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/fragment/app/FragmentManager.BackStackEntry` Representation of an entry on the fragment back stack, as created with `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#addToBackStack(java.lang.String)`. |
| `public abstract class https://developer.android.com/reference/androidx/fragment/app/FragmentManager.FragmentLifecycleCallbacks` Callback interface for listening to fragment state changes that happen within a given FragmentManager. |
| `public interface https://developer.android.com/reference/androidx/fragment/app/FragmentManager.OnBackStackChangedListener` Interface to watch for changes to the back stack. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#POP_BACK_STACK_INCLUSIVE() = 1` Flag for `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStack(java.lang.String,int)` and `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#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 |
|---|
| `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#FragmentManager()()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#addFragmentOnAttachListener(androidx.fragment.app.FragmentOnAttachListener)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentOnAttachListener listener)` Add a `https://developer.android.com/reference/androidx/fragment/app/FragmentOnAttachListener` that should receive a call to `https://developer.android.com/reference/androidx/fragment/app/FragmentOnAttachListener#onAttachFragment(androidx.fragment.app.FragmentManager,androidx.fragment.app.Fragment)` when a new Fragment is attached to this FragmentManager. |
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#addOnBackStackChangedListener(androidx.fragment.app.FragmentManager.OnBackStackChangedListener)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentManager.OnBackStackChangedListener listener )` Add a new listener for changes to the fragment back stack. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#beginTransaction()()` Start a series of edit operations on the Fragments associated with this FragmentManager. |
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#clearBackStack(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html name)` Clears the back stack previously saved via `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#saveBackStack(java.lang.String)`. |
| `final void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#clearFragmentResult(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html requestKey)` Clears the stored result for the given requestKey. |
| `final void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#clearFragmentResultListener(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html requestKey)` Clears the stored `https://developer.android.com/reference/androidx/fragment/app/FragmentResultListener` for the given requestKey. |
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#dump(java.lang.String,java.io.FileDescriptor,java.io.PrintWriter,java.lang.String[])( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html prefix, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/io/FileDescriptor.html fd, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/io/PrintWriter.html writer, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html String[] args )` Print the FragmentManager's state into the given stream. |
| `static void` | `[enableDebugLogging](https://developer.android.com/reference/androidx/fragment/app/FragmentManager#enableDebugLogging(boolean))(boolean enabled)` **This method is deprecated.** FragmentManager now respects `https://developer.android.com/reference/android/util/Log.html#isLoggable(java.lang.String, int)` for debug logging, allowing you to use `adb shell setprop log.tag.FragmentManager VERBOSE`. <br /> |
| `static void` | `@https://developer.android.com/reference/androidx/fragment/app/PredictiveBackControl https://developer.android.com/reference/androidx/fragment/app/FragmentManager#enablePredictiveBack(boolean)(boolean enabled)` Control whether FragmentManager uses the new state predictive back feature that allows seeing the previous Fragment when using gesture back. |
| `boolean` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/fragment/app/FragmentManager#executePendingTransactions()()` After a `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` is committed with `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#commit()`, it is scheduled to be executed asynchronously on the process's main thread. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html F` | `<F extends https://developer.android.com/reference/androidx/fragment/app/Fragment> https://developer.android.com/reference/androidx/fragment/app/FragmentManager#findFragment(android.view.View)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html view)` Find a `https://developer.android.com/reference/androidx/fragment/app/Fragment` associated with the given `https://developer.android.com/reference/android/view/View.html`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/fragment/app/Fragment` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#findFragmentById(int)(@https://developer.android.com/reference/androidx/annotation/IdRes 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. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/fragment/app/Fragment` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#findFragmentByTag(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html tag)` Finds a fragment that was identified by the given tag either when inflated from XML or as supplied when added in a transaction. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentManager` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#findFragmentManager(android.view.View)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html view)` Recurse up the view hierarchy, looking for a FragmentManager |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentManager.BackStackEntry` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#getBackStackEntryAt(int)(int index)` Return the BackStackEntry at index <var translate="no">index</var> in the back stack; entries start index 0 being the bottom of the stack. |
| `int` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#getBackStackEntryCount()()` Return the number of entries currently in the back stack. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/fragment/app/Fragment` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#getFragment(android.os.Bundle,java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html bundle, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html key)` Retrieve the current Fragment instance for a reference previously placed with `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#putFragment(android.os.Bundle,java.lang.String,androidx.fragment.app.Fragment)`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentFactory` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#getFragmentFactory()()` Gets the current `https://developer.android.com/reference/androidx/fragment/app/FragmentFactory` used to instantiate new Fragment instances. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/fragment/app/Fragment>` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#getFragments()()` Get a list of all fragments that are currently added to the FragmentManager. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/fragment/app/Fragment` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#getPrimaryNavigationFragment()()` Return the currently active primary navigation fragment for this FragmentManager. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode.Policy` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#getStrictModePolicy()()` Returns the current policy for this FragmentManager. |
| `boolean` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#isDestroyed()()` Returns true if the final `https://developer.android.com/reference/android/app/Activity.html#onDestroy()` call has been made on the FragmentManager's Activity, so this instance is now dead. |
| `boolean` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#isStateSaved()()` Returns `true` if the FragmentManager's state has already been saved by its host. |
| `final void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#onContainerAvailable(androidx.fragment.app.FragmentContainerView)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentContainerView container)` Callback for when the `https://developer.android.com/reference/androidx/fragment/app/FragmentContainerView` becomes available in the view hierarchy and the fragment manager can add the fragment view to its hierarchy. |
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStack()()` Pop the top state off the back stack. |
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStack(int,int)(int id, int flags)` Pop all back stack states up to the one with the given identifier. |
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStack(java.lang.String,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html name, int flags)` Pop the last fragment transition from the manager's fragment back stack. |
| `boolean` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStackImmediate()()` Like `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStack()`, but performs the operation immediately inside of the call. |
| `boolean` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStackImmediate(int,int)(int id, int flags)` Like `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStack(int,int)`, but performs the operation immediately inside of the call. |
| `boolean` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStackImmediate(java.lang.String,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html name, int flags)` Like `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStack(java.lang.String,int)`, but performs the operation immediately inside of the call. |
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#putFragment(android.os.Bundle,java.lang.String,androidx.fragment.app.Fragment)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html bundle, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html key, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/Fragment fragment )` Put a reference to a fragment in a Bundle. |
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#registerFragmentLifecycleCallbacks(androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks,boolean)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentManager.FragmentLifecycleCallbacks cb, boolean recursive )` Registers a `https://developer.android.com/reference/androidx/fragment/app/FragmentManager.FragmentLifecycleCallbacks` to listen to fragment lifecycle events happening in this FragmentManager. |
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#removeFragmentOnAttachListener(androidx.fragment.app.FragmentOnAttachListener)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentOnAttachListener listener )` Remove a `https://developer.android.com/reference/androidx/fragment/app/FragmentOnAttachListener` that was previously added via `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#addFragmentOnAttachListener(androidx.fragment.app.FragmentOnAttachListener)`. |
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#removeOnBackStackChangedListener(androidx.fragment.app.FragmentManager.OnBackStackChangedListener)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentManager.OnBackStackChangedListener listener )` Remove a listener that was previously added with `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#addOnBackStackChangedListener(androidx.fragment.app.FragmentManager.OnBackStackChangedListener)`. |
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#restoreBackStack(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html name)` Restores the back stack previously saved via `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#saveBackStack(java.lang.String)`. |
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#saveBackStack(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html name)` Save the back stack. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/fragment/app/Fragment.SavedState` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#saveFragmentInstanceState(androidx.fragment.app.Fragment)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/Fragment fragment)` Save the current instance state of the given Fragment. |
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#setFragmentFactory(androidx.fragment.app.FragmentFactory)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentFactory fragmentFactory)` Set a `https://developer.android.com/reference/androidx/fragment/app/FragmentFactory` for this FragmentManager that will be used to create new Fragment instances from this point onward. |
| `final void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#setFragmentResult(java.lang.String,android.os.Bundle)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html requestKey, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html result)` Sets the given result for the requestKey. |
| `final void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#setFragmentResultListener(java.lang.String,androidx.lifecycle.LifecycleOwner,androidx.fragment.app.FragmentResultListener)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html requestKey, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner lifecycleOwner, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentResultListener listener )` Sets the `https://developer.android.com/reference/androidx/fragment/app/FragmentResultListener` for a given requestKey. |
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#setStrictModePolicy(androidx.fragment.app.strictmode.FragmentStrictMode.Policy)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode.Policy policy)` Sets the policy for what actions should be detected, as well as the penalty if such actions occur. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#toString()()` |
| `void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#unregisterFragmentLifecycleCallbacks(androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentManager.FragmentLifecycleCallbacks cb )` Unregisters a previously registered `https://developer.android.com/reference/androidx/fragment/app/FragmentManager.FragmentLifecycleCallbacks`. |

| ### Extension functions |
|---|---|
| `final void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManagerKt.https://developer.android.com/reference/androidx/fragment/app/FragmentManager#(androidx.fragment.app.FragmentManager).commit(kotlin.Boolean,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentManager receiver, boolean allowStateLoss, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> body )` Run `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commit(kotlin.Boolean,kotlin.Function1)` in a `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` which is automatically committed if it completes without exception. |
| `final void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/fragment/app/FragmentManagerKt.https://developer.android.com/reference/androidx/fragment/app/FragmentManager#(androidx.fragment.app.FragmentManager).commitNow(kotlin.Boolean,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentManager receiver, boolean allowStateLoss, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> body )` Run `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commitNow(kotlin.Boolean,kotlin.Function1)` in a `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` which is automatically committed if it completes without exception. |
| `final void` | `https://developer.android.com/reference/androidx/fragment/app/FragmentManagerKt.[transaction](https://developer.android.com/reference/androidx/fragment/app/FragmentManager#(androidx.fragment.app.FragmentManager).transaction(kotlin.Boolean,kotlin.Boolean,kotlin.Function1))( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentManager receiver, boolean now, boolean allowStateLoss, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> body )` **This method is deprecated.** Use commit { .. } or commitNow { .. } extensions |

## Constants

### POP_BACK_STACK_INCLUSIVE

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public static final int POP_BACK_STACK_INCLUSIVE = 1
```

Flag for `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStack(java.lang.String,int)` and `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#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.

## Public constructors

### FragmentManager

Added in 1.1.0

```
public FragmentManager()
```

## Public methods

### addFragmentOnAttachListener

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.3.0)

```
public void addFragmentOnAttachListener(@NonNull FragmentOnAttachListener listener)
```

Add a `https://developer.android.com/reference/androidx/fragment/app/FragmentOnAttachListener` that should receive a call to `https://developer.android.com/reference/androidx/fragment/app/FragmentOnAttachListener#onAttachFragment(androidx.fragment.app.FragmentManager,androidx.fragment.app.Fragment)` when a new Fragment is attached to this FragmentManager.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentOnAttachListener listener` | Listener to add |

### addOnBackStackChangedListener

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public void addOnBackStackChangedListener(
    @NonNull FragmentManager.OnBackStackChangedListener listener
)
```

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

### beginTransaction

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public @NonNull 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 `https://developer.android.com/reference/androidx/activity/ComponentActivity#onSaveInstanceState(android.os.Bundle)` (and prior to a following `https://developer.android.com/reference/androidx/fragment/app/FragmentActivity#onStart()` or `https://developer.android.com/reference/androidx/fragment/app/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.

### clearBackStack

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.4.0)

```
public void clearBackStack(@NonNull String name)
```

Clears the back stack previously saved via `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#saveBackStack(java.lang.String)`. This will result in all of the transactions that made up that back stack to be thrown away, thus destroying any fragments that were added through those transactions. All state of those fragments will be cleared as part of this process. If no state was previously saved with the given name, this operation does nothing.

This function is asynchronous -- it enqueues the request to clear, but the action will not be performed until the application returns to its event loop.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html name` | The name of the back stack previously saved by `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#saveBackStack(java.lang.String)`. |

### clearFragmentResult

```
public final void clearFragmentResult(@NonNull String requestKey)
```

Clears the stored result for the given requestKey. This clears any result that was previously set via `https://developer.android.com/reference/androidx/fragment/app/FragmentResultOwner#setFragmentResult(java.lang.String,android.os.Bundle)` that hasn't yet been delivered to a `https://developer.android.com/reference/androidx/fragment/app/FragmentResultListener`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html requestKey` | key used to identify the result |

### clearFragmentResultListener

```
public final void clearFragmentResultListener(@NonNull String requestKey)
```

Clears the stored `https://developer.android.com/reference/androidx/fragment/app/FragmentResultListener` for the given requestKey. This clears any `https://developer.android.com/reference/androidx/fragment/app/FragmentResultListener` that was previously set via `https://developer.android.com/reference/androidx/fragment/app/FragmentResultOwner#setFragmentResultListener(java.lang.String,androidx.lifecycle.LifecycleOwner,androidx.fragment.app.FragmentResultListener)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html requestKey` | key used to identify the result |

### dump

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public void dump(
    @NonNull String prefix,
    @Nullable FileDescriptor fd,
    @NonNull PrintWriter writer,
    @Nullable String[] args
)
```

Print the FragmentManager's state into the given stream.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html prefix` | Text to print at the front of each line. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/io/FileDescriptor.html fd` | The raw file descriptor that the dump is being sent to. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/io/PrintWriter.html writer` | A PrintWriter to which the dump is to be set. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html String[] args` | Additional arguments to the dump request. |

### enableDebugLogging

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0) Deprecated in [1.2.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.2.0)

```
public static void [enableDebugLogging](https://developer.android.com/reference/androidx/fragment/app/FragmentManager#enableDebugLogging(boolean))(boolean enabled)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> FragmentManager now respects `https://developer.android.com/reference/android/util/Log.html#isLoggable(java.lang.String, int)` for debug logging, allowing you to use `adb shell setprop log.tag.FragmentManager VERBOSE`.

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.

| See also |
|---|---|
| `https://developer.android.com/reference/android/util/Log.html#isLoggable(java.lang.String, int)` |   |

### enablePredictiveBack

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.7.0)

```
@PredictiveBackControl
public static void enablePredictiveBack(boolean enabled)
```

Control whether FragmentManager uses the new state predictive back feature that allows seeing the previous Fragment when using gesture back.

This should only be changed **before** any fragment transactions are done (i.e., in your `Application` class or prior to `super.onCreate()` in every activity).

| Parameters |
|---|---|
| `boolean enabled` | Whether predictive back should be enabled. |

### executePendingTransactions

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
@MainThread
public boolean executePendingTransactions()
```

After a `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` is committed with `https://developer.android.com/reference/androidx/fragment/app/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 `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#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 `https://developer.android.com/reference/androidx/fragment/app/Fragment#postponeEnterTransition()` has been called.

| Returns |
|---|---|
| `boolean` | Returns true if there were any pending transactions to be executed. |

### findFragment

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.2.0)

```
public static @NonNull F <F extends Fragment> findFragment(@NonNull View view)
```

Find a `https://developer.android.com/reference/androidx/fragment/app/Fragment` associated with the given `https://developer.android.com/reference/android/view/View.html`. This method will locate the `https://developer.android.com/reference/androidx/fragment/app/Fragment` associated with this view. This is automatically populated for the View returned by `https://developer.android.com/reference/androidx/fragment/app/Fragment#onCreateView(android.view.LayoutInflater,android.view.ViewGroup,android.os.Bundle)` and its children.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html view` | the view to search from |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html F` | the locally scoped `https://developer.android.com/reference/androidx/fragment/app/Fragment` to the given view |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the given view does not correspond with a `https://developer.android.com/reference/androidx/fragment/app/Fragment`. |

### findFragmentById

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public @Nullable Fragment findFragmentById(@IdRes 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.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/fragment/app/Fragment` | The fragment if found or null otherwise. |

### findFragmentByTag

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public @Nullable Fragment findFragmentByTag(@Nullable 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.

If provided a `null` tag, this method returns null.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html tag` | the tag used to search for the fragment |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/fragment/app/Fragment` | The fragment if found or null otherwise. |

### findFragmentManager

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.8.0)

```
public static @NonNull FragmentManager findFragmentManager(@NonNull View view)
```

Recurse up the view hierarchy, looking for a FragmentManager

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html view` | the view to search from |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentManager` | The containing `https://developer.android.com/reference/androidx/fragment/app/FragmentManager` of the given view. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if there no Fragment associated with the view and the view's context is not a `https://developer.android.com/reference/androidx/fragment/app/FragmentActivity`. |

### getBackStackEntryAt

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public @NonNull FragmentManager.BackStackEntry getBackStackEntryAt(int index)
```

Return the BackStackEntry at index <var translate="no">index</var> in the back stack; entries start index 0 being the bottom of the stack.

### getBackStackEntryCount

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public int getBackStackEntryCount()
```

Return the number of entries currently in the back stack.

### getFragment

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public @Nullable Fragment getFragment(@NonNull Bundle bundle, @NonNull String key)
```

Retrieve the current Fragment instance for a reference previously placed with `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#putFragment(android.os.Bundle,java.lang.String,androidx.fragment.app.Fragment)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html bundle` | The bundle from which to retrieve the fragment reference. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html key` | The name of the entry in the bundle. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/fragment/app/Fragment` | Returns the current Fragment instance that is associated with the given reference. |

### getFragmentFactory

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public @NonNull FragmentFactory getFragmentFactory()
```

Gets the current `https://developer.android.com/reference/androidx/fragment/app/FragmentFactory` used to instantiate new Fragment instances.

If no factory has been explicitly set on this FragmentManager via `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#setFragmentFactory(androidx.fragment.app.FragmentFactory)`, the FragmentFactory of the `https://developer.android.com/reference/androidx/fragment/app/Fragment#getParentFragmentManager()` will be returned.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentFactory` | the current FragmentFactory |

### getFragments

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public @NonNull List<Fragment> 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.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/fragment/app/Fragment>` | A list of all fragments that are added to the FragmentManager. |

### getPrimaryNavigationFragment

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public @Nullable Fragment getPrimaryNavigationFragment()
```

Return the currently active primary navigation fragment for this FragmentManager. The primary navigation fragment is set by fragment transactions using `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#setPrimaryNavigationFragment(androidx.fragment.app.Fragment)`.

The primary navigation fragment's `https://developer.android.com/reference/androidx/fragment/app/Fragment#getChildFragmentManager()` will be called first to process delegated navigation actions such as `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStack()` if no ID or transaction name is provided to pop to.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/fragment/app/Fragment` | the fragment designated as the primary navigation fragment |

### getStrictModePolicy

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.4.0)

```
public @Nullable FragmentStrictMode.Policy getStrictModePolicy()
```

Returns the current policy for this FragmentManager. If no policy is set, returns null.

### isDestroyed

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public boolean isDestroyed()
```

Returns true if the final `https://developer.android.com/reference/android/app/Activity.html#onDestroy()` call has been made on the FragmentManager's Activity, so this instance is now dead.

### isStateSaved

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public boolean isStateSaved()
```

Returns `true` if the FragmentManager's state has already been saved by its host. Any operations that would change saved state should not be performed if this method returns true. For example, any popBackStack() method, such as `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStackImmediate()` or any FragmentTransaction using `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#commit()` instead of `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#commitAllowingStateLoss()` will change the state and will result in an error.

| Returns |
|---|---|
| `boolean` | true if this FragmentManager's state has already been saved by its host |

### onContainerAvailable

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.8.0)

```
public final void onContainerAvailable(@NonNull FragmentContainerView container)
```

Callback for when the `https://developer.android.com/reference/androidx/fragment/app/FragmentContainerView` becomes available in the view hierarchy and the fragment manager can add the fragment view to its hierarchy.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentContainerView container` | the container that the active fragment should add their views to |

### popBackStack

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

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

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

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

| Parameters |
|---|---|
| `int id` | Identifier of the stated to be popped. If no identifier exists, false is returned. The identifier is the number returned by `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#commit()`. The `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#POP_BACK_STACK_INCLUSIVE()` flag can be used to control whether the named state itself is popped. |
| `int flags` | Either 0 or `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#POP_BACK_STACK_INCLUSIVE()`. |

### popBackStack

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public void popBackStack(@Nullable 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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html 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 `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#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. |
| `int flags` | Either 0 or `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#POP_BACK_STACK_INCLUSIVE()`. |

### popBackStackImmediate

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
@MainThread
public boolean popBackStackImmediate()
```

Like `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStack()`, but performs the operation immediately inside of the call. This is like calling `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#executePendingTransactions()` afterwards without forcing the start of postponed Transactions.

| Returns |
|---|---|
| `boolean` | Returns true if there was something popped, else false. |

### popBackStackImmediate

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public boolean popBackStackImmediate(int id, int flags)
```

Like `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStack(int,int)`, but performs the operation immediately inside of the call. This is like calling `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#executePendingTransactions()` afterwards without forcing the start of postponed Transactions.

| Returns |
|---|---|
| `boolean` | Returns true if there was something popped, else false. |

### popBackStackImmediate

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
@MainThread
public boolean popBackStackImmediate(@Nullable String name, int flags)
```

Like `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStack(java.lang.String,int)`, but performs the operation immediately inside of the call. This is like calling `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#executePendingTransactions()` afterwards without forcing the start of postponed Transactions.

| Returns |
|---|---|
| `boolean` | Returns true if there was something popped, else false. |

### putFragment

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public void putFragment(
    @NonNull Bundle bundle,
    @NonNull String key,
    @NonNull Fragment fragment
)
```

Put a reference to a fragment in a Bundle. This Bundle can be persisted as saved state, and when later restoring `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#getFragment(android.os.Bundle,java.lang.String)` will return the current instance of the same fragment.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html bundle` | The bundle in which to put the fragment reference. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html key` | The name of the entry in the bundle. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/Fragment fragment` | The Fragment whose reference is to be stored. |

### registerFragmentLifecycleCallbacks

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public void registerFragmentLifecycleCallbacks(
    @NonNull FragmentManager.FragmentLifecycleCallbacks cb,
    boolean recursive
)
```

Registers a `https://developer.android.com/reference/androidx/fragment/app/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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentManager.FragmentLifecycleCallbacks cb` | Callbacks to register |
| `boolean recursive` | true to automatically register this callback for all child FragmentManagers |

### removeFragmentOnAttachListener

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.3.0)

```
public void removeFragmentOnAttachListener(
    @NonNull FragmentOnAttachListener listener
)
```

Remove a `https://developer.android.com/reference/androidx/fragment/app/FragmentOnAttachListener` that was previously added via `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#addFragmentOnAttachListener(androidx.fragment.app.FragmentOnAttachListener)`. It will no longer get called when a new Fragment is attached.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentOnAttachListener listener` | Listener to remove |

### removeOnBackStackChangedListener

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public void removeOnBackStackChangedListener(
    @NonNull FragmentManager.OnBackStackChangedListener listener
)
```

Remove a listener that was previously added with `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#addOnBackStackChangedListener(androidx.fragment.app.FragmentManager.OnBackStackChangedListener)`.

### restoreBackStack

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.4.0)

```
public void restoreBackStack(@NonNull String name)
```

Restores the back stack previously saved via `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#saveBackStack(java.lang.String)`. This will result in all of the transactions that made up that back stack to be re-executed, thus re-adding any fragments that were added through those transactions. All state of those fragments will be restored as part of this process. If no state was previously saved with the given name, this operation does nothing.

This function is asynchronous -- it enqueues the request to restore, but the action will not be performed until the application returns to its event loop.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html name` | The name of the back stack previously saved by `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#saveBackStack(java.lang.String)`. |

### saveBackStack

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.4.0)

```
public void saveBackStack(@NonNull String name)
```

Save the back stack. While this functions similarly to `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#popBackStack(java.lang.String,int)`, it **does not** throw away the state of any fragments that were added through those transactions. Instead, the back stack that is saved by this method can later be restored with its state in tact.

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html name` | The name set by `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#addToBackStack(java.lang.String)`. |

### saveFragmentInstanceState

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public @Nullable Fragment.SavedState saveFragmentInstanceState(@NonNull Fragment fragment)
```

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 `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#putFragment(android.os.Bundle,java.lang.String,androidx.fragment.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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/Fragment fragment` | The Fragment whose state is to be saved. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/fragment/app/Fragment.SavedState` | The generated state. This will be null if there was no interesting state created by the fragment. |

### setFragmentFactory

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public void setFragmentFactory(@NonNull FragmentFactory fragmentFactory)
```

Set a `https://developer.android.com/reference/androidx/fragment/app/FragmentFactory` for this FragmentManager that will be used to create new Fragment instances from this point onward.

The `https://developer.android.com/reference/androidx/fragment/app/Fragment#getChildFragmentManager()` of all Fragments in this FragmentManager will also use this factory if one is not explicitly set.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentFactory fragmentFactory` | the factory to use to create new Fragment instances |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/fragment/app/FragmentManager#getFragmentFactory()` |   |

### setFragmentResult

```
public final void setFragmentResult(@NonNull String requestKey, @NonNull Bundle result)
```

Sets the given result for the requestKey. This result will be delivered to a `https://developer.android.com/reference/androidx/fragment/app/FragmentResultListener` that is called given to `https://developer.android.com/reference/androidx/fragment/app/FragmentResultOwner#setFragmentResultListener(java.lang.String,androidx.lifecycle.LifecycleOwner,androidx.fragment.app.FragmentResultListener)` with the same requestKey. If no `https://developer.android.com/reference/androidx/fragment/app/FragmentResultListener` with the same key is set or the Lifecycle associated with the listener is not at least `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#STARTED`, the result is stored until one becomes available, or `https://developer.android.com/reference/androidx/fragment/app/FragmentResultOwner#clearFragmentResult(java.lang.String)` is called with the same requestKey.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html requestKey` | key used to identify the result |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html result` | the result to be passed to another fragment |

### setFragmentResultListener

```
public final void setFragmentResultListener(
    @NonNull String requestKey,
    @NonNull LifecycleOwner lifecycleOwner,
    @NonNull FragmentResultListener listener
)
```

Sets the `https://developer.android.com/reference/androidx/fragment/app/FragmentResultListener` for a given requestKey. Once the given `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` is at least in the `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#STARTED` state, any results set by `https://developer.android.com/reference/androidx/fragment/app/FragmentResultOwner#setFragmentResult(java.lang.String,android.os.Bundle)` using the same requestKey will be delivered to the `https://developer.android.com/reference/androidx/fragment/app/FragmentResultListener#onFragmentResult(java.lang.String,android.os.Bundle)`. The callback will remain active until the LifecycleOwner reaches the `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#DESTROYED` state or `https://developer.android.com/reference/androidx/fragment/app/FragmentResultOwner#clearFragmentResultListener(java.lang.String)` is called with the same requestKey.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html requestKey` | requestKey used to identify the result |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner lifecycleOwner` | lifecycleOwner for handling the result |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentResultListener listener` | listener for result changes |

### setStrictModePolicy

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.4.0)

```
public void setStrictModePolicy(@Nullable FragmentStrictMode.Policy policy)
```

Sets the policy for what actions should be detected, as well as the penalty if such actions occur. The `https://developer.android.com/reference/androidx/fragment/app/Fragment#getChildFragmentManager()` of all Fragments in this FragmentManager will also use this policy if one is not explicitly set. Pass null to clear the policy.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/fragment/app/strictmode/FragmentStrictMode.Policy policy` | the policy to put into place |

### toString

```
public @NonNull String toString()
```

### unregisterFragmentLifecycleCallbacks

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
public void unregisterFragmentLifecycleCallbacks(
    @NonNull FragmentManager.FragmentLifecycleCallbacks cb
)
```

Unregisters a previously registered `https://developer.android.com/reference/androidx/fragment/app/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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/fragment/app/FragmentManager.FragmentLifecycleCallbacks cb` | Callbacks to unregister |

## Extension functions

### FragmentManagerKt.commit

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentManager.kt+function:commit)

```
public final void FragmentManagerKt.commit(
    @NonNull FragmentManager receiver,
    boolean allowStateLoss,
    @NonNull Function1<@NonNull FragmentTransaction, Unit> body
)
```

Run `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commit(kotlin.Boolean,kotlin.Function1)` in a `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` which is automatically committed if it completes without exception.

The transaction will be completed by calling `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#commit()` unless `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commit(kotlin.Boolean,kotlin.Function1)` is set to `true` in which case `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#commitAllowingStateLoss()` will be used.

### FragmentManagerKt.commitNow

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentManager.kt+function:commitNow)

```
@MainThread
public final void FragmentManagerKt.commitNow(
    @NonNull FragmentManager receiver,
    boolean allowStateLoss,
    @NonNull Function1<@NonNull FragmentTransaction, Unit> body
)
```

Run `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commitNow(kotlin.Boolean,kotlin.Function1)` in a `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` which is automatically committed if it completes without exception.

The transaction will be completed by calling `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#commitNow()` unless `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).commitNow(kotlin.Boolean,kotlin.Function1)` is set to `true` in which case `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction#commitNowAllowingStateLoss()` will be used.

### FragmentManagerKt.transaction

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentManager.kt+function:transaction)

```
public final void FragmentManagerKt.[transaction](https://developer.android.com/reference/androidx/fragment/app/FragmentManager#(androidx.fragment.app.FragmentManager).transaction(kotlin.Boolean,kotlin.Boolean,kotlin.Function1))(
    @NonNull FragmentManager receiver,
    boolean now,
    boolean allowStateLoss,
    @NonNull Function1<@NonNull FragmentTransaction, Unit> body
)
```

> [!CAUTION]
> **This method is deprecated.**   
> Use commit { .. } or commitNow { .. } extensions

Run `https://developer.android.com/reference/androidx/fragment/app/package-summary#(androidx.fragment.app.FragmentManager).transaction(kotlin.Boolean,kotlin.Boolean,kotlin.Function1)` in a `https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction` which is automatically committed if it completes without exception.

One of four commit functions will be used based on the values of `now` and `allowStateLoss`:

```
|  now  |  allowStateLoss  | Method                         |
| --- | --- | --- |
| false | false            |  commit()                      |
| false | true             |  commitAllowingStateLoss()     |
| true  | false            |  commitNow()                   |
| true  | true             |  commitNowAllowingStateLoss()  |
```