我試圖將數據保存在我的活動中並進行恢復。 我將數據保存在onSaveInstanceState()
上,然後嘗試恢復onRestoreInstanceState()
中的數據。爲什麼onRestoreInstanceState()永遠不會被調用
我設置了斷點,方法onSaveInstanceState()
被調用。但onRestoreInstanceState()
或onCreate()
從來沒有。
這裏是我的步驟:
- 開始我
Activity
。 - 按手機上的'Home'按鈕。打電話給
onSaveInstanceState()
。 - 單擊啓動器中的圖標並再次啓動我的
Activity
。
此時,只有onRestart()
被調用。但不是onRestoreInstanceState()
或onCreate()
。
有誰知道爲什麼嗎?
http://stackoverflow.com/questions/4967435/onrestoreinstancestate-not-called-when-screen-wake-up - 有一個答案是什麼onRestoreInstanceState是。 – jellyfish 2011-05-13 14:37:10
你的回答不完全準確,或者至少不清楚,因爲在onStop()之後要麼調用onRestart(),要麼調用onDestroy()。如果onDestroy()被調用,那麼你回到onCreate() – LuxuryMode 2012-01-11 19:28:18
謝謝。 onRestore ...在方向改變時似乎被調用。簡化的東西對我來說沒有結束(+: – Everyone 2012-11-09 18:08:38