2

I have a deep, nested, fragment application. When I use the below code all works.

fragmentManager.popBackStack("root", FragmentManager.POP_BACK_STACK_INCLUSIVE);

However I want to keep the root fragment so I call

fragmentManager.popBackStack("root", 0);

But it doens't work, the Stack is the same. I'm sure that "root" is present because when I use the first code all is done in the right way.

Blodhgard
  • 9,130
  • 3
  • 24
  • 36
  • If you always want to keep the root, you can just omit the addToBackStack() call when you originally add the root fragment. Otherwise I think you probably need to find the back-stack name of the fragment on top of the root. You can look through the entries (which are NOT fragment instances!) using backStackEntryCount() and getBackStackEntryAt(). – mrrrk May 10 '19 at 10:50

1 Answers1

3

there's a trick to pop everything, just:

fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
Budius
  • 39,391
  • 16
  • 102
  • 144