当“不要保持活动”时找不到ID查找被打开 [英] No View Found for ID when "Don't Keep Activities" Is Turned On

查看:295
本文介绍了当“不要保持活动”时找不到ID查找被打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在一些闲置后间歇性地崩溃。所以我想我没有正确地存储东西。我打开不要保持活动进行故障排除,现在我的应用程序正在崩溃。

My app was crashing intermittently after some inactivity. So i figured I wasn't storing things correctly. I turned on "Don't Keep Activities" to troubleshoot and now my app is crashing everywhere.

堆栈跟踪: https://gist.github.com/hanleyhansen/6d41fee54b1e129b7922
这是缺少的布局: https://gist.github.com/hanleyhansen/73ace0c99ae675023e0f

推荐答案

我认为您正在经历第19917期。这个bug存在于3.2及更高版本中,最近才被修改(4.2)。同样的修复程序还没有到达支持库。

I think you are experiencing a likely symptom of Issue 19917. This bug exists in 3.2 and higher and was only fixed recently (4.2). This same fix hasn't made its way in to the support library, yet.

查看评论28 为一个真正的修复:您将需要编辑您的支持库并重新编译。编辑v4 / java / android / support / v4 / app / FragmentManager.java

Check out comment 28 for a real fix: you'll want to edit your support library and recompile. edit v4/java/android/support/v4/app/FragmentManager.java

Bundle saveFragmentBasicState(Fragment f) {
    Bundle result = null;

    if (mStateBundle == null) {
        mStateBundle = new Bundle();
    }
    f.onSaveInstanceState(mStateBundle);
    if (!mStateBundle.isEmpty()) {
        result = mStateBundle;
        mStateBundle = null;
    }

    if (f.mView != null) {
        saveFragmentViewState(f);
    }
    if (f.mSavedViewState != null) {
        if (result == null) {
            result = new Bundle();
        }
        result.putSparseParcelableArray(
                FragmentManagerImpl.VIEW_STATE_TAG, f.mSavedViewState);
    }
    if (!f.mUserVisibleHint) {
        // Only add this if it's not the default value
        // @@@ BUG, result may not have been created, can be null!
        if (result == null) {
            result = new Bundle();
        }
        result.putBoolean(FragmentManagerImpl.USER_VISIBLE_HINT_TAG, f.mUserVisibleHint);
    }

    return result;
}

如果您不了解任务,并希望等待Google修复支持库
这里是另一个解决方法
评论8 修复可以适用于所有的片段

If you dont feel up to the task and want to wait for Google to fix the support library here is another workaround Comment 8 for fix you can apply to all your fragments

    @Override
    public void onSaveInstanceState(Bundle outState) {
        //first saving my state, so the bundle wont be empty.
        //http://code.google.com/p/android/issues/detail?id=19917
        outState.putString("WORKAROUND_FOR_BUG_19917_KEY", "WORKAROUND_FOR_BUG_19917_VALUE");
        super.onSaveInstanceState(outState);
    }

我也遇到过 transaction.commitAllowingStateLoss ); 作为修复而不是 transaction.commit();

I've also come across transaction.commitAllowingStateLoss(); as a "fix" for this instead of transaction.commit();

其他一些背景信息和解决方法我发现这些相关的帮助我解决了片段问题(尤其是嵌套时)

Some other background info and workaround I've found that are related that helped me with fragment issues (esp. when nesting them)

  • TNR's answer to java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState with DialogFragment (decent workaround)
  • How to fix "Can not perform this action after onSaveInstanceState" on Android Fragments ]4 (very informative)
  • Chris Jenkins answer to Do fragments really need an empty constructor?

这篇关于当“不要保持活动”时找不到ID查找被打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆