onRestoreInstanceState not called when screen wake up?

放肆的年华 提交于 2019-11-28 10:14:49

问题


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, onSaveInstanceState is called and everything goes well. On screen on, onRestoreInstanceState is not called, neither onCreate, only onResume.

Am I missing something?


回答1:


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




回答2:


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




回答3:


Its also called while zoom pressing (for example on Tablet).



来源:https://stackoverflow.com/questions/4967435/onrestoreinstancestate-not-called-when-screen-wake-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!