android - fragment 有时会在返回堆栈时保存变量

标签 android android-fragments

我在从服务器调用填充的 fragment 上有一个 ArrayList,如果我导航到其他 fragment 并在某些设备上返回此 fragment 后检查集合大小,则列表为空,而在某些设备上则不是。

当 fragment 进入返回堆栈时究竟发生了什么?

最佳答案

根据 documentation

Stopped

The fragment is not visible. Either the host activity has been stopped or the fragment has been removed from the activity but added to the back stack. A stopped fragment is still alive (all state and member information is retained by the system). However, it is no longer visible to the user and will be killed if the activity is killed.

一旦停止,它们就有资格被销毁。

关于android - fragment 有时会在返回堆栈时保存变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38235693/

相关文章:

Android - Facebook SDK 4.30 初始化

android - Fragment交易到底在哪里实现?

android - 无法查看 RecyclerView 中的条目

android - 如何使用 android 更改我的数据库 firebase 的多个子节点

android - 日期选择器“确定/取消”按钮文本已更改为牛轧糖中的其他语言(Moto G4 plus)

android - 获取ArtifactoryPublication的BuildType版本名称

android - 在 JNI/OpenGL ES 加载代码期间,非常规和狡猾的 Android 崩溃

android - 使用 FragmentStatePagerAdapter 后 fragment 中的重复菜单和数据

android - 没有提交的 fragment 事务

java - 改造错误: Service methods cannot return void message