1

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.

buczek
  • 2,011
  • 7
  • 29
  • 40
chitra
  • 77
  • 9

1 Answers1

1

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);

Community
  • 1
  • 1
ade.akinyede
  • 2,214
  • 1
  • 13
  • 17
  • That works like a charm thanks! UPDATE: though its working like i wanted but doesnt really clear all the stack. Sorry, if you dont mind me asking , where exactly do i add this code? – chitra Apr 27 '16 at 22:38
  • You'd have to add some code in order to have a clearer idea. Although going by your description, I suppose you want it done in `onBackPressed`. – ade.akinyede Apr 28 '16 at 08:25