java - "Don' t Keep Activities“打开时找不到 ID 的 View

标签 java android eclipse android-view

我的应用在不活动后间歇性崩溃。所以我想我没有正确存储东西。我打开“不保留 Activity ”进行故障排除,但现在我的应用程序到处崩溃。

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

最佳答案

我认为您可能遇到了 Issue 19917 的症状.此错误存在于 3.2 及更高版本中,并且最近才得到修复 (4.2)。同样的修复程序还没有进入支持库。

查看 comment 28一个真正的修复:你会想要编辑你的支持库并重新编译。编辑 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 修复支持库 这是另一个解决方法 Comment 8对于修复,您可以将其应用于所有 fragment

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

我发现的一些其他相关背景信息和解决方法可以帮助我解决 fragment 问题(尤其是在嵌套它们时)

关于java - "Don' t Keep Activities“打开时找不到 ID 的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17416263/

相关文章:

java - 将另一个子项目作为依赖项编译 gradle 子项目

java - android应用程序的内存分配问题

eclipse - 如何在eclipse中全局添加jboss存储库到maven?

eclipse - git 会忽略文件名中的大小写更改吗?

java - 为什么jDateChooser的值又回到默认值了?

java.text.ParseException : Unparseable date from ("d MMM yyyy kk:mm:ss zzz")

android - 使用 id : corona SDK 调用 transition.to

android - Android studio 中存储在 SVN checkout 中的 Eclipse 项目

java - 绑定(bind)数据触发更改后 Swing/JTable 不更新

java - 按名称的对象和方法