Created
October 7, 2018 11:02
-
-
Save NezSpencer/1b08b9ea65d0812dcd56375b399b0085 to your computer and use it in GitHub Desktop.
move back x times in fragment backstack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun moveBackXTimes(numOfTimes : Int) { | |
if (!lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) | |
return | |
val backStackCount = supportFragmentManager.backStackEntryCount | |
if (numOfTimes >= backStackCount) { | |
throw UnsupportedOperationException("Number of times specified $numOfTimes is greater" + | |
" than the backstackEntryCount") | |
} | |
val fragment = supportFragmentManager.getBackStackEntryAt(backStackCount - numOfTimes) | |
supportFragmentManager.popBackStackImmediate(fragment::class.simpleName, 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment