8
votes

How to make the maximum stack size in 5 fragments. Adding 6 fragment, 1 fragment should be deleted, but quietly, without showing screen.

[Fragment1]->[Fragment2]->[Fragment3]->[Fragment4]->[Fragment5]

Added 6 fragment

[Fragment1][Fragment2]->[Fragment3]->[Fragment4]->[Fragment5]->[Fragment6]

when the user will come back he will be on 5 screens.

The main problem, how to remove FragmentManager.BackStackEntry from the back stack fragment manager in a quiet, not pushing on the screen.

Is this possible ?

1
My question as well .. I guess we need to use own custom stack - abdfahim

1 Answers

0
votes

The Fragment back stack is indeed a stack where the only available options are:

  • push, which adds an element to the collection, and
  • pop, which removes the most recently added element that was not yet removed.

Therefore removing Fragments from the bottom of the stack is not a supported operation. You'd need to manage your own back stack (by overriding onBackPressed() and using attach()/detach() operations) to provide this effect.