onSaveInstanceState() and onPause() call sequence

前端 未结 3 1379
迷失自我
迷失自我 2021-01-18 21:41

The documentation on onSaveInstanceState() states:

If the method is called, it is always called before onStop() and possibly before onPa

3条回答
  •  悲哀的现实
    2021-01-18 22:36

    Please help me understand in what circumstances does onSaveInstanceState() is called before onPause()

    There is a difference in the Activity lifecycle between the pre-HONEYCOMB and the other platforms (since HONEYCOMB onwards):

    API level >= 11: when onPause() is called, the process is in a safe state, it can't be killed.

    API level < 11 : when onPause() is called, the process that hosts the Activity becomes killable. It means that the system can kill the process, that contains the activity, without executing any other line of code. So if this happens the onSaveInstanceState() may never be called. In order to avoid this, the system should call onSaveInstanceState() before onPause(), otherwise you will not able to save the user state.

提交回复
热议问题