gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:27:25 24 4
gpt4 key购买 nike

我的应用在不活动后间歇性崩溃。所以我想我没有正确存储东西。我打开“不保留 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com