0

I want resume fragment state as follows.

I have 5 fragments A,B,C,D,E. if user open fragment like A ---> B ---> C ---> D ---> E . using default back stack,back key it works fine. But when user opens A ---> B ---> C ---> D ---> E ---> B. After this if user click back, default back stack will goes to A.

So i need to save top fragments or reorder stack

1 Answers1

0

As suggested here you can simply hide and show other fragments

You can hide your 2nd and 3rd fragment and make your 1st fragment visible. > So you'll have the effect that first fragment is shown on top and others are invisible.

solution:

Use the FragmentTransaction's show and hide method. Firs you need to find all the fragment and call the FragmentTransaction to show and hide 2nd and 3rd fragments.

So, you can call hide on C, D and E fragments, showing the B fragment.

After this, you intercept the "onBackPressed" and you show again the hidden ones

Hope this helps

Community
  • 1
  • 1
Pier Giorgio Misley
  • 5,305
  • 4
  • 27
  • 66