YoKeyword / Fragmentation

[DEPRECATED] A powerful library that manage Fragment for Android
Apache License 2.0
9.73k stars 2.11k forks source link

launcher应用从后台切回前进程dead,重新创建后仍然显示之前界面 #1155

Open litingting-bj opened 5 years ago

litingting-bj commented 5 years ago

Issues Guideline

Following information can help us to resolve the issue faster.

In addition, we do not accept issues unrelated to Fragmentation. 使用wechat demo类型,切后台一段时间该app进程被杀,切回前台总是走mFragments == null分支,如果所有的child fragment都重新创建,仍然会停在切后台前的界面,tab切换时所有逻辑都走了,但界面就是没任何变化。除了重启,还有其他更好的方式吗?

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    ByLog.d(TAG, "onActivityCreated");
    SupportFragment firstFragment = findChildFragment(HomeFragment.class);
    if (firstFragment == null) {
     // create later
    } else {
        if(mFragments == null ) {
            ToastUtils.showShort("mFragments 资源被回收!");
            Log.e(TAG, "onActivityCreated recycled");
            popChild();
            restartApp();
        } else {
            // 这里库已经做了Fragment恢复,所有不需要额外的处理了, 不会出现重叠问题
            // 这里我们需要拿到mFragments的引用
            mFragments[FIRST] = findChildFragment(FirstFragment.class);
            mFragments[SECOND] = findChildFragment(SecondFragment.class);
            mFragments[THIRD] = findChildFragment(HomeFragment.class);
            mFragments[FOURTH] = findChildFragment(Fourthragment.class);
            mFragments[FIFTH] = findChildFragment(FifthFragment.class);
            mFragments[SIXTH] = findChildFragment(SixthFragment.class);
        }
    }
}
NiceNicks commented 5 years ago

image

建议你在根activity 重写onSaveInstanceState 然后注释掉super.onSaveInstanceState(outState) 根治你的一切重启为空的问题。