[英]No View Found for ID when “Don't Keep Activities” Is Turned On
我的應用程序在一些不活動后間歇性地崩潰。 所以我想我沒有正確存放東西。 我打開了“不要保持活動”進行故障排除,現在我的應用程序無處不在。
堆棧跟蹤: https : //gist.github.com/hanleyhansen/6d41fee54b1e129b7922這是缺少的布局: https : //gist.github.com/hanleyhansen/73ace0c99ae675023e0f
我認為您正在遇到問題19917的可能症狀。 這個bug存在於3.2及更高版本中,最近才修復(4.2)。 但是,同樣的修復還沒有進入支持庫。
查看評論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;
}
如果您不理解任務並且想要等待谷歌修復支持庫,這是另一種解決方法評論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);
}
我也遇到了transaction.commitAllowingStateLoss();
作為“修復”而不是transaction.commit();
我發現其他一些背景信息和解決方法是相關的,這有助於我解決碎片問題(特別是在嵌套時)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.