# FragmentManager.OnBackStackChangedListener

# FragmentManager.OnBackStackChangedListener

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.OnBackStackChangedListener)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/fragment/app/FragmentManager.OnBackStackChangedListener "View this page in Java")

<br />

```
interface FragmentManager.OnBackStackChangedListener
```

<br />

*** ** * ** ***

Interface to watch for changes to the back stack.

## Summary

|                             ### Public functions                              |
|-------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | `@`[MainThread](https://developer.android.com/reference/kotlin/androidx/annotation/MainThread) [onBackStackChangeCancelled](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.OnBackStackChangedListener#onBackStackChangeCancelled())`()` Called whenever a predictive back gesture is cancelled.                                                                                                                                                                                                                                                                                                                 |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | `@`[MainThread](https://developer.android.com/reference/kotlin/androidx/annotation/MainThread) [onBackStackChangeCommitted](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.OnBackStackChangedListener#onBackStackChangeCommitted(androidx.fragment.app.Fragment,boolean))`(fragment: `[Fragment](https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment)`, pop: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Called whenever the contents of a back stack change is committed.                                                                |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | `@`[MainThread](https://developer.android.com/reference/kotlin/androidx/annotation/MainThread) [onBackStackChangeProgressed](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.OnBackStackChangedListener#onBackStackChangeProgressed(androidx.activity.BackEventCompat))`(backEventCompat: `[BackEventCompat](https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat)`)` Called whenever a predictive back gesture is changing the back stack.                                                                                                                                          |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | `@`[MainThread](https://developer.android.com/reference/kotlin/androidx/annotation/MainThread) [onBackStackChangeStarted](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.OnBackStackChangedListener#onBackStackChangeStarted(androidx.fragment.app.Fragment,boolean))`(fragment: `[Fragment](https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment)`, pop: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Called whenever the contents of the back stack are starting to be changed, before any fragment actually changes its lifecycle state. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | `@`[MainThread](https://developer.android.com/reference/kotlin/androidx/annotation/MainThread) [onBackStackChanged](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.OnBackStackChangedListener#onBackStackChanged())`()` Called whenever the contents of the back stack change, after the fragment manager has moved all of the fragments to their final state.                                                                                                                                                                                                                                                  |

## Public functions

### onBackStackChangeCancelled

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

```
@MainThread
fun onBackStackChangeCancelled(): Unit
```

Called whenever a predictive back gesture is cancelled.

This is called immediately after[onBackStackChangeProgressed](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.OnBackStackChangedListener#onBackStackChangeProgressed(androidx.activity.BackEventCompat))once a predictive back gesture has been cancelled and will place the FragmentManager back into the state before the predictive back gesture was started.  

### onBackStackChangeCommitted

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

```
@MainThread
fun onBackStackChangeCommitted(fragment: Fragment, pop: Boolean): Unit
```

Called whenever the contents of a back stack change is committed. If this is caused by a forward transaction and the given fragment is incoming, it will return`false`from[isRemoving](https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment#isRemoving()). If this is caused by a pop operation and the given fragment is being popped, it will return`true`from[isRemoving](https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment#isRemoving()).

This is called immediately after[onBackStackChangeStarted](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.OnBackStackChangedListener#onBackStackChangeStarted(androidx.fragment.app.Fragment,boolean))for a forward transaction or for a non-predictive back pop. If this is caused by a predictive back gesture, it will be called after[onBackStackChangeProgressed](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.OnBackStackChangedListener#onBackStackChangeProgressed(androidx.activity.BackEventCompat))before the fragment moves to the final state.  

|                                              Parameters                                               |
|-------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------|
| `fragment: `[Fragment](https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment) | one of the fragments that is affected by the committed back stack change |
| `pop: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)            | true, if this callback was triggered by a pop operation, false otherwise |

### onBackStackChangeProgressed

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

```
@MainThread
fun onBackStackChangeProgressed(backEventCompat: BackEventCompat): Unit
```

Called whenever a predictive back gesture is changing the back stack. This will continue to be called with an updated[BackEventCompat](https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat)object until the gesture is either cancelled or completed.

This is called immediately after[onBackStackChangeStarted](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.OnBackStackChangedListener#onBackStackChangeStarted(androidx.fragment.app.Fragment,boolean))during a predictive back gesture. If the gesture is completed, this will be followed by[onBackStackChangeCommitted](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.OnBackStackChangedListener#onBackStackChangeCommitted(androidx.fragment.app.Fragment,boolean))and if it is cancelled, it will be followed by[onBackStackChangeCancelled](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.OnBackStackChangedListener#onBackStackChangeCancelled()).  

|                                                       Parameters                                                       |
|------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| `backEventCompat: `[BackEventCompat](https://developer.android.com/reference/kotlin/androidx/activity/BackEventCompat) | provides the current progress of the active predictive back gesture |

### onBackStackChangeStarted

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

```
@MainThread
fun onBackStackChangeStarted(fragment: Fragment, pop: Boolean): Unit
```

Called whenever the contents of the back stack are starting to be changed, before any fragment actually changes its lifecycle state. If this is caused by a forward transaction and the given fragment is incoming, it will return`false`from[isRemoving](https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment#isRemoving()). If this is caused by a pop operation and the given fragment is being popped, it will return`true`from[isRemoving](https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment#isRemoving()).

This is the first callback that will be delivered to the listener. If the transaction is caused by a predictive back gesture, it will be followed by an[onBackStackChangeProgressed](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.OnBackStackChangedListener#onBackStackChangeProgressed(androidx.activity.BackEventCompat))callback otherwise, the next callback will be[onBackStackChangeCommitted](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.OnBackStackChangedListener#onBackStackChangeCommitted(androidx.fragment.app.Fragment,boolean)).  

|                                              Parameters                                               |
|-------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------|
| `fragment: `[Fragment](https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment) | one of the fragments that is affected by the starting back stack change  |
| `pop: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)            | true, if this callback was triggered by a pop operation, false otherwise |

### onBackStackChanged

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

```
@MainThread
fun onBackStackChanged(): Unit
```

Called whenever the contents of the back stack change, after the fragment manager has moved all of the fragments to their final state.

This is the final callback that will be delivered to the listener in all cases except for when the predictive back gesture is cancelled. It will be called after[onBackStackChangeCommitted](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager.OnBackStackChangedListener#onBackStackChangeCommitted(androidx.fragment.app.Fragment,boolean)).