Clear Fragment back stack

  1. Home
  2. chevron_right
  3. Snippets
  4. chevron_right
  5. Clear Fragment back stack

Clear Fragment back stack

To clear the Fragments back stack of a FragmentManager, you could iterate through all back stack items and call popBackStack() but there is also a more elegant solution.
Please see below:

// in my case I get the support fragment manager, it should work with the native one too
 FragmentManager fragmentManager = getSupportFragmentManager();
 // this will clear the back stack and displays no animation on the screen
 fragmentManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);

Good luck!

, ,
Previous Post
Run code on main/UI thread on android
Next Post
Android Gradle & Manifest merge

Related Posts

Menu