總結了下:
oncreate是在onstart之前執行是activity聲明週期,而onRestoreInstanceState 是在onstart之後onresume之前執行。
stackoverflow上看到的一個比較好的解釋:
onRestoreInstanceState is redundant because you can easily restore state in onCreate.
Having said that here is what the official doc says for onRestoreInstanceState:
Most implementations will simply use onCreate(Bundle) to restore their state, but it is sometimes convenient to do it here after all of the initialization has been done or to allow subclasses to decide whether to use your default implementation.
So for best practice, lay out your view hierarchy in onCreate and restore the previous state in onRestoreInstanceState. If you do that, anyone who subclasses your Activity can chose to override your onRestoreInstanceState to augment or replace your restore state logic. This is a long way of saying onRestoreInstanceState serves as a template method.
大致意思就是: