获得从backstack为了所有片段 [英] Get all fragments from backstack in order

查看:164
本文介绍了获得从backstack为了所有片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的片段我的应用程序的项目。所有的片段被添加到返回堆栈

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

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

后来,什么是正确的方式来获得返回堆栈所有片段的顺序?

推荐答案

使用 getBackStackEntryCount()则可以通过背部栈遍历,并使用 getBackStackEntryAt()方法来获取每一个片段。

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

编辑: 基于在评论一些讨论,但我还是建议你手动存储已添加到您的backstack的片段的列表,并保存这些到您的共享preferences。然后,您可以读取该列表后面的应用程序启动时,并重新加载这些片段。

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.

这篇关于获得从backstack为了所有片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆