-2
我想在SavedInstanceState中傳遞多個值。這可以做到嗎?如何在SavedInstanceState中傳遞多個值
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putInt(KEY_INDEX, array_counter);
savedInstanceState.putInt(SAVED_ANSWER, answer);
savedInstanceState.putInt(SAVED_VALUE, value);
}
但在OnCreate中接收他們時,他們都具有相同的價值:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
array_counter = savedInstanceState.getInt(KEY_INDEX);
answer = savedInstanceState.getInt(SAVED_ANSWER);
value = savedInstanceState.getInt(SAVED_VALUE);
}
明顯的原因:'KEY_INDEX.equals(SAVED_ANSWER)&& SAVED_ANSWER.equals(SAVED_VALUE)'...或者你認爲'onSaveInstanceState'用於保存(這是真的......但是它只被系統用於某些原因)... – Selvin
KEY_INDEX,SAVED_ANSWER,SAVED_VALUE的值是什麼? –