我試圖保存下列數據捆綁數據:無法的onSaveInstanceState中
@Override
public void setMessageDetailsExpanded(MessageHeaderItem i, boolean expanded,
int heightBefore) {
mDiff = (expanded ? 1 : -1) * Math.abs(i.getHeight() - heightBefore);
String mHeaderItem = i.toString();
final boolean mDetailsExpanded = expanded;
int mHeightBefore = heightBefore;
}
當設置斷點上面我看到的數據,我想包:
mMessageHeaderItem = co[email protected]425a6f40
detailsExpanded = true
heightBefore = 229
然而當在onSaveInstanceState處設置斷點時 - 看起來我的輸出不包含上面的數據?!
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putFloat(BUNDLE_KEY_WEBVIEW_Y_PERCENT, calculateScrollYPercent());
outState.putBoolean(getTag(), mDetailsExpanded);
outState.putInt(getTag(), height);
outState.putString(getTag(), mHeaderItem);
}
Im not sure why but for some reason when debugging the code above it contains the following:
mDetailsExpanded = False
height = 0
mHeaderItem = null
我知道我俯瞰小東西 - 但我似乎無法弄清楚,爲什麼我沒有從setMessageDetailsExpanded
我捆在onSavedInstanceState
保存數據。
完整的源:
你確定嗎?他們把之後(如本): http://sunil-android.blogspot.com/: http://pastebin.com/GW2VfkrR 似乎並沒有按照我所看到的每一個例子是正確的2013/03/save-and-restore-instance-state.html http://android-am.blogspot.com/2012/11/android-saved-instance-state-bundle.html –
這裏是谷歌的例子,完成我建議的方式http://developer.android.com/training/basics/activity-lifecycle/recreating.html – Shooky
謝謝!我很感激...我改變了我的代碼流以反映你的 - 但我仍然無法得到正確的數據值。一切總是返回mDetailsExpanded =假 高度= 0 mHeaderItem = NULL 當它應該是mMessageHeaderItem = co[email protected]425a6f40 detailsExpanded =真 heightBefore = 229 所以 - 我保存和恢復不正確的值:( 這是我的完整源(剛纔更新),如果有幫助: http://pastebin.com/Larzbwzh –