FragmentManager:moveToState:GridFragment {...}的片段状态未更新为内联; 预期状态1找到0

Evg*_*tin 5 android android-fragments

我有一个简单的Activity和Retained Fragment,就像Alex Lockwood的博客文章一样.

我的活动内容如下onCreate():

FragmentManager fm = getSupportFragmentManager();
    retainedFragment = (GridFragment) fm.findFragmentByTag(RETAINED_FRAGMENT_TAG);

    // If the Fragment is non-null, then it is currently being
    // retained across a configuration change.
    if (retainedFragment == null) {
        retainedFragment = new GridFragment();
        fm.beginTransaction().add(retainedFragment, RETAINED_FRAGMENT_TAG).commit();
    }else{
        list = retainedFragment.getList();
        System.out.println(list.size());//OUTPUT 12
    }
Run Code Online (Sandbox Code Playgroud)

我的Fragments' onAttach()是:

 @Override
public void onAttach(Context activity) {
    super.onAttach(activity);
    mCallbacks = (TaskCallbacks) activity;
    System.out.println("here"); //OUTPUT here
}
Run Code Online (Sandbox Code Playgroud)

现在,在每个屏幕旋转我都有非常奇怪的输出:

I/System.out:这里

W/FragmentManager:moveToState:GridFragment {95fc9db#0 retained_tag}的片段状态未内联更新; 预期状态1找到0

I/System.out:12

这个奇怪的警告来自我的输入之间?怎么处理呢?提前致谢!

mbe*_*sky 8

此消息无关紧要,支持库v24.0.0中删除了额外的日志这是官方开发人员的回答:

好奇的是,FragmentManager.moveToState现在更新新的片段状态,而不是在所有状态更改阶段完成后的最后.这解决了在父片段的一个生命周期回调中使用子片段管理器和executePendingTransactions的几个有趣的错误.

我们带来一个片段的状态转换之一就是一个无操作状态,它没有让状态更新为内联,你看到的日志就是宣布我们最后完成了它,就像我们一样在23.2之前.