什么时候不调用 onRestoreInstanceState?

When onRestoreInstanceState is not called?

Docs 描述何时调用 onRestoreInstanceState

This method is called after onStart() when the activity is being re-initialized from a previously saved state, given here in savedInstanceState. (...) This method is called between onStart() and onPostCreate(Bundle). This method is called only when recreating an activity; the method isn't invoked if onStart() is called for any other reason.

我很好奇“onStart() 被称为 出于任何其他原因”在 onRestoreInstanceState 的上下文中是什么意思?

Activity 的正常生命周期如下所示:

  • onCreate()
  • .
  • onStart()
  • onResume()
  • onPause()
  • onStop()
  • .
  • onDestroy()

如果 Activity 被另一个 Activity 完全遮挡,onStart()onStop() 之间的生命周期回调可能会反复发生。在这种情况下,当 Activity 被另一个 Activity 完全遮挡时,将调用 onStop()。当 Activity 再次可见时,onStart() 将被调用 onRestoreInstanceState() 不会被调用 因为 Activity 不会被重新创建。