具体清空如下:
1、 使用add,show,hide方式操作fragment
2、activity崩溃迅速重启,并且重启成功
这个时候 可以发现第一个fragment是OK的, 后面的fragment对象不为空,但是里面的数据没有了(我没有用savedInstanceState,不知道情况如何)。
分析:
当act重启的时候 fragment数据会被清空,猜测fragment执行的周期变了。此时只需要再activity中使用
@Override
public void recreate() {
try {//避免重启太快 恢复
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.remove(recommendFrg);
fragmentTransaction.remove(catalogFrg);
fragmentTransaction.commitAllowingStateLoss();
} catch (Exception e) {
}
super.recreate();
}在重新创建的时候 将manager中的fragment清空
本文探讨了在Activity重启过程中Fragment数据丢失的问题。通过分析发现,在Activity重启后,虽然Fragment对象存在,但内部数据丢失。为解决该问题,文章提供了一种在Activity重启时清除FragmentManager中Fragment的方法。
2306

被折叠的 条评论
为什么被折叠?



