android - FragmentManager : moveToState: Fragment state for GridFragment{. ..} 未内联更新;预期状态 1 找到 0

标签 android android-fragments

我有一个简单的 Activity 和 Retained Fragment,就像 Alex Lockwood blog post example .

我的 Activity 在 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
    }

我的 Fragments' onAttach() 是:

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

现在,在每次屏幕旋转时,我都会得到非常奇怪的输出:

I/System.out: here

W/FragmentManager: moveToState: Fragment state for GridFragment{95fc9db #0 retained_tag} not updated inline; expected state 1 found 0

I/System.out: 12

在我的输入之间那个奇怪的警告来自哪里?如何处理?提前致谢!

最佳答案

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

For the curious, FragmentManager.moveToState now updates the new fragment state as it goes rather than at the end after all of the state change phases have completed. This fixed several interesting bugs around using the child fragment manager and executePendingTransactions from within one of the parent fragment's lifecycle callbacks.

One of the state transitions as we're bringing a fragment up is a no-op that wasn't getting the state updated inline, and the log you're seeing is announcing that we did it at the end instead, exactly as we would have prior to 23.2.

关于android - FragmentManager : moveToState: Fragment state for GridFragment{. ..} 未内联更新;预期状态 1 找到 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37125731/

相关文章:

android - 按下后退按钮时 AsyncTask 终止任务

android - 从 Android 调用 Google Cloud Endpoints API 时出现错误 413(请求实体太大)

android - fragment 内的 Kotlin 按钮 onClickListener 事件

android - Fragments 什么时候有非空的 savedInstanceState

android - 媒体播放器 : error (-19, 0)

android - 在 Android 中使用 Trace View

java - 如何从外部存储目录输出不带扩展名的文件?

java - 从 fragment 启动 Activity ,然后获取回调

java - 对话框中的Viewpager?

Android 5 屏幕故障/静态与 Viewpager 内的 Google map fragment