onRestoreInstanceState not called when screen wake up?
I've wrote all the needed code to save my Activity state (a simple form with EditText widgets) and restore it on phone rotation and it works great.
My problem is on managing screen on/off changes: when going off, onSa开发者_开发问答veInstanceState is called and everything goes well. On screen on, onRestoreInstanceState is not called, neither onCreate, only onResume.
Am I missing something?
The onRestoreInstanceState method is called only if the activity process is killed(due to memory constraints or some other reasons) and then restored when it becomes visible again. On the phone rotation, the activity is killed and restored with different orientation so it will work. But on screen on/off it wouldn't be the case. The activity has not been destroyed so no need for restore
onRestoreInstanceState is called to save the state of the activity before being killed. When the screen goes off, the activity is put in a pause state - because the keyguard is an activity that come in front of your activity. to catch the screen off/on cycle, to have to override onPause / onResume methods, as stated in http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle
Its also called while zoom pressing (for example on Tablet).
精彩评论