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!

keyboard_arrow_up