简体   繁体   English

当“不保持活动”打开时,找不到ID的视图

[英]No View Found for ID when “Don't Keep Activities” Is Turned On

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. 我打开了“不要保持活动”进行故障排除,现在我的应用程序无处不在。

Stack trace: https://gist.github.com/hanleyhansen/6d41fee54b1e129b7922 This is the layout that goes missing: https://gist.github.com/hanleyhansen/73ace0c99ae675023e0f 堆栈跟踪: https//gist.github.com/hanleyhansen/6d41fee54b1e129b7922这是缺少的布局: https//gist.github.com/hanleyhansen/73ace0c99ae675023e0f

I think you are experiencing a likely symptom of Issue 19917 . 我认为您正在遇到问题19917的可能症状。 This bug exists in 3.2 and higher and was only fixed recently (4.2). 这个bug存在于3.2及更高版本中,最近才修复(4.2)。 This same fix hasn't made its way in to the support library, yet. 但是,同样的修复还没有进入支持库。

Check out comment 28 for a real fix: you'll want to edit your support library and recompile. 查看评论28以获得真正的修复:您需要编辑支持库并重新编译。 edit v4/java/android/support/v4/app/FragmentManager.java 编辑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;
}

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 如果您不理解任务并且想要等待谷歌修复支持库,这是另一种解决方法评论8修复您可以应用于您的所有片段

    @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);
    }

I've also come across transaction.commitAllowingStateLoss(); 我也遇到了transaction.commitAllowingStateLoss(); as a "fix" for this instead of transaction.commit(); 作为“修复”而不是transaction.commit();

Some other background info and workaround I've found that are related that helped me with fragment issues (esp. when nesting them) 我发现其他一些背景信息和解决方法是相关的,这有助于我解决碎片问题(特别是在嵌套时)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM