赞
踩
描述:4个Activity页面 配合launcheMode: singleTask、 singleInstance,查看对应生命周期调用
AActivity,CActivity,DActivity luanchMode 都是standard,指修改BActivity。
结论:
当B页面luanchMode为singleTask,栈中已经有B页面时,再启动B页面会销毁B页面之上的所有页面
当B页面luanchMode为singleInstance,栈中已经有B页面时,再启动B页面不会销毁B页面之上的所有页面
----------------------------------------------------
下面是通过打印生命周期日志的方式,方便理解对应生命周期调用。
BActivity launchMode:singleTask
依次打开页面:AActivity->BActivity->CActivity->DActivity
对应生命周期:
- 依次启动A->B->C->D
- 2019-04-22 11:37:01.705 AActivity-onCreate
- 2019-04-22 11:37:01.752 AActivity-onStart
- 2019-04-22 11:37:01.758 AActivity-onResume
- 2019-04-22 11:37:02.787 AActivity-onPause
- 2019-04-22 11:37:02.822 BActivity-onCreate
- 2019-04-22 11:37:02.867 BActivity-onStart
- 2019-04-22 11:37:02.871 BActivity-onResume
- 2019-04-22 11:37:03.417 AActivity-onSaveInstanceState
- 2019-04-22 11:37:03.418 AActivity-onStop
- 2019-04-22 11:37:03.917 BActivity-onPause
- 2019-04-22 11:37:03.944 CActivity-onCreate
- 2019-04-22 11:37:03.983 CActivity-onStart
- 2019-04-22 11:37:03.986 CActivity-onResume
- 2019-04-22 11:37:04.568 BActivity-onSaveInstanceState
- 2019-04-22 11:37:04.569 BActivity-onStop
- 2019-04-22 11:37:04.873 CActivity-onPause
- 2019-04-22 11:37:04.907 DActivity-onCreate
- 2019-04-22 11:37:04.948 DActivity-onStart
- 2019-04-22 11:37:04.951 DActivity-onResume
- 2019-04-22 11:37:05.476 CActivity-onSaveInstanceState
- 2019-04-22 11:37:05.477 CActivity-onStop
通过D页面启动B页面
D->B
- 2019-04-22 11:37:32.767 CActivity-onDestroy
- 2019-04-22 11:37:32.783 DActivity-onPause
- 2019-04-22 11:37:32.806 BActivity-OnNewIntent
- 2019-04-22 11:37:32.808 BActivity-onRestart
- 2019-04-22 11:37:32.809 BActivity-onStart
- 2019-04-22 11:37:32.810 BActivity-onResume
- 2019-04-22 11:37:33.314 DActivity-onStop
- 2019-04-22 11:37:33.314 DActivity-onDestroy
注意是C页面先进行Destroy,然后才是D页面
B页面点击back键依次关闭:
目前栈上只有AB 两个页面,CD已经销毁。
B->A
- B页面点击Back键,先是页面是A页面
- 2019-04-22 11:38:02.802 BActivity-onPause
- 2019-04-22 11:38:02.832 AActivity-onRestart
- 2019-04-22 11:38:02.833 AActivity-onStart
- 2019-04-22 11:38:02.835 AActivity-onResume
- 2019-04-22 11:38:03.381 BActivity-onStop
- 2019-04-22 11:38:03.382 BActivity-onDestroy
- A页面点击back键
- 2019-04-22 11:38:04.935 AActivity-onPause
- 2019-04-22 11:38:05.486 AActivity-onStop
- 2019-04-22 11:38:05.486 AActivity-onDestroy
BActivity launchMode:singleInstance
依次打开页面:AActivity->BActivity->CActivity->DActivity
对应生命周期:
- 启动A页面
- 2019-04-22 11:24:30.652 AActivity-onCreate
- 2019-04-22 11:24:30.702 AActivity-onStart
- 2019-04-22 11:24:30.706 AActivity-onResume
- 通过A启动B页面
- 2019-04-22 11:24:33.348 AActivity-onPause
- 2019-04-22 11:24:33.420 BActivity-onCreate
- 2019-04-22 11:24:33.469 BActivity-onStart
- 2019-04-22 11:24:33.475 BActivity-onResume
- 2019-04-22 11:24:33.944 AActivity-onSaveInstanceState
- 2019-04-22 11:24:33.945 AActivity-onStop
- 通过B启动C页面
- 2019-04-22 11:24:34.608 BActivity-onPause
- 2019-04-22 11:24:34.638 CActivity-onCreate
- 2019-04-22 11:24:34.681 CActivity-onStart
- 2019-04-22 11:24:34.685 CActivity-onResume
- 2019-04-22 11:24:35.374 BActivity-onSaveInstanceState
- 2019-04-22 11:24:35.375 BActivity-onStop
- 通过C启动D页面
- 2019-04-22 11:24:35.700 CActivity-onPause
- 2019-04-22 11:24:35.734 DActivity-onCreate
- 2019-04-22 11:24:35.768 DActivity-onStart
- 2019-04-22 11:24:35.771 DActivity-onResume
- 2019-04-22 11:24:36.297 CActivity-onSaveInstanceState
- 2019-04-22 11:24:36.297 CActivity-onStop
通过D页面打开B页面
D->B
- 通过D打开B页面,调用B页面的OnNewIntent方法,并没有重新create一个B页面
- 2019-04-22 11:28:30.137 DActivity-onPause
- 2019-04-22 11:28:30.157 BActivity-OnNewIntent
- 2019-04-22 11:28:30.160 BActivity-onRestart
- 2019-04-22 11:28:30.161 BActivity-onStart
- 2019-04-22 11:28:30.162 BActivity-onResume
- 2019-04-22 11:28:30.780 DActivity-onSaveInstanceState
- 2019-04-22 11:28:30.781 DActivity-onStop
通过打印日志查看 当BActivity launcheMode为singleInstance时,后面打开的C,D页面并没有被销毁。
点击Back键依次关闭页面
B->D->C->A
- 点击Back键,依次关闭页面
- 关闭B页面
- 2019-04-22 11:29:14.765 BActivity-onPause
- 2019-04-22 11:29:14.793 DActivity-onRestart
- 2019-04-22 11:29:14.794 DActivity-onStart
- 2019-04-22 11:29:14.796 DActivity-onResume
- 2019-04-22 11:29:15.461 BActivity-onStop
- 2019-04-22 11:29:15.462 BActivity-onDestroy
- 关闭D页面
- 2019-04-22 11:29:16.785 DActivity-onPause
- 2019-04-22 11:29:16.816 CActivity-onRestart
- 2019-04-22 11:29:16.817 CActivity-onStart
- 2019-04-22 11:29:16.819 CActivity-onResume
- 2019-04-22 11:29:17.353 DActivity-onStop
- 2019-04-22 11:29:17.354 DActivity-onDestroy
- 关闭C页面
- 2019-04-22 11:29:19.337 CActivity-onPause
- 2019-04-22 11:29:19.364 AActivity-onRestart
- 2019-04-22 11:29:19.366 AActivity-onStart
- 2019-04-22 11:29:19.367 AActivity-onResume
- 2019-04-22 11:29:19.882 CActivity-onStop
- 2019-04-22 11:29:19.883 CActivity-onDestroy
- 关闭A页面
- 2019-04-22 11:29:23.387 AActivity-onPause
- 2019-04-22 11:29:23.961 AActivity-onStop
- 2019-04-22 11:29:23.961 AActivity-onDestroy
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。