onSaveInstanceState、onRestoreInstanceState、onNewIntent调用时机

onSaveInstanceState是在Activity还有机会被显示的时候被调用(比如从ActivityA打开另外一个ActivityB,或者切换横竖屏导致ActivityA被销毁重建),在Activity被正常销毁的时候不会被调用(直接调用finish()的情况),调用时机是:onStop()之前被调用,与onPause()没有严格的前后顺序关系

onRestoreInstanceState数据恢复并且保证Bundle有值的时候,调用时机是在onStart()之后

onNewIntent:对于singleTask、singleTop、sigleInstance的Activity来说,如果位于位于栈顶,onPause()->onNewIntent()->onResume(),对于sigleTask的Activity来说,如果启动模式为singleTask的ActivityA启动启动普通模式的ActivityB,并在ActivityB中启动ActivityA,调用顺序为:ActivityB onPause()->ActivityA onNewIntent()->ActivityA onRestart()->ActivityA onStart()->ActivityA onResume()->ActivityB onStop()->ActivityB onDestroy()

特殊一些的是如果singleInstance的ActivityA启动ActivityB,并在ActivityB中启动ActivityA,那么调用顺序为:ActivityB onPause()->ActivityA onNewIntent()->ActivityA onRestart()->ActivityA onStart()->ActivityA onResume()->ActivityB onSaveInstance()->ActivityB onStop()(经测试)

你可能感兴趣的:(Android)