When exactly are onSaveInstanceState() and onRestoreInstanceState() called?

前端 未结 5 1382
梦如初夏
梦如初夏 2020-11-28 20:14

The following figure (from the official doc) describes the well-known lifecycle of an Android activity:

5条回答
  •  半阙折子戏
    2020-11-28 20:29

    As per doc1 and doc2

    onSaveInstanceState

    Prior to Honeycomb, activities were not considered killable until after they had been paused, meaning that onSaveInstanceState() was called immediately before onPause(). Beginning with Honeycomb, however, Activities are considered to be killable only after they have been stopped, meaning that onSaveInstanceState() will now be called before onStop() instead of immediately before onPause().

    onRestoreInstanceState

    This method is called between onStart() and onPostCreate(Bundle) when the activity is being re-initialized from a previously saved state

提交回复
热议问题