Skip to content

Instantly share code, notes, and snippets.

@NezSpencer
Created October 13, 2018 13:21
Show Gist options
  • Save NezSpencer/485ff64561d18e46c707a318c047c36e to your computer and use it in GitHub Desktop.
Save NezSpencer/485ff64561d18e46c707a318c047c36e to your computer and use it in GitHub Desktop.
pop off all fragments after the specified fragment, including the specified fragment
private fun popToFragmentBeforeKnownFragment(fragment: Fragment) {
if (!lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED))
return
val isPopped = supportFragmentManager.popBackStackImmediate(fragment::class.simpleName,
FragmentManager.POP_BACK_STACK_INCLUSIVE)
if (!isPopped)
throw UnsupportedOperationException("Specified fragment does not exist in backstack")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment