Get all fragments from backstack in order

淺唱寂寞╮ 提交于 2019-12-21 05:16:23

问题


I am using Fragments in my app project. All the fragments are added to back stack:

...
fragmentTransaction.addToBackStack(null);
...

Later on, what is the correct way to get all fragments from back stack in order ?


回答1:


Using the getBackStackEntryCount() you can iterate through the back stack and use the getBackStackEntryAt() method to get each Fragment.

EDIT: Based on some discussions in the comments, it is advised that you manually store a list of the Fragments you have added to your backstack, and persist these into your SharedPreferences. You can then read this list back when the application starts, and reload these fragments.



来源:https://stackoverflow.com/questions/9772790/get-all-fragments-from-backstack-in-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!