简体   繁体   中英

How to resume backstack fragment with out removing top fragments?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM