Search code examples
androidandroid-fragmentsnavigation-draweronbackpressed

Clear back stack when navigation drawer is opened


How can I clear the back stack excluding the home screen when the navigation drawer is opened?

Additional information: I only have 2 activities. I am mostly working with fragments. I have a navigation button in the action bar. When I back-press my activity shows previously unwanted fragments. I want to clear all the fragments when I open the drawer.


Solution

  • Your answer is here:

    Is this the right way to clean-up Fragment back stack when leaving a deeply nested stack?

    Essentially, what you want is getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);