启动A,重新打开A界面(我这里点击两次):
打印出来的各自的生命周期事件:
当我从A->B->C->D->A,点击返回按钮(A->D->C->B->A),事件是:
文件清单添加;
android:launchMode="singleTop"
启动A,重新打开A界面(我这里点击两次):
singleTop与standard的启动模式是相似的,但是有一点不同的是,singleTop,将要启动的目标activity如果在栈顶时,系统将不会重新创建该activity的实例而是直接复用。
A->B->C->D->A:
LOG:
2020-07-03 14:09:33.203 16086-16086/com.example.test_01 I/A界面: onCreate
2020-07-03 14:09:33.205 16086-16086/com.example.test_01 I/A界面: onStart
2020-07-03 14:09:33.206 16086-16086/com.example.test_01 I/A界面: onResume
2020-07-03 14:09:56.207 16086-16086/com.example.test_01 I/A界面: onPause
2020-07-03 14:09:56.228 16086-16086/com.example.test_01 I/B界面: onCreate
2020-07-03 14:09:56.229 16086-16086/com.example.test_01 I/B界面: onStart
2020-07-03 14:09:56.231 16086-16086/com.example.test_01 I/B界面: onResume
2020-07-03 14:09:56.648 16086-16086/com.example.test_01 I/A界面: onStop
2020-07-03 14:10:10.651 16086-16086/com.example.test_01 I/B界面: onPause
2020-07-03 14:10:10.670 16086-16086/com.example.test_01 I/C界面: onCreate
2020-07-03 14:10:10.671 16086-16086/com.example.test_01 I/C界面: onStart
2020-07-03 14:10:10.672 16086-16086/com.example.test_01 I/C界面: onResume
2020-07-03 14:10:11.093 16086-16086/com.example.test_01 I/B界面: onStop
2020-07-03 14:10:22.405 16086-16086/com.example.test_01 I/C界面: onPause
2020-07-03 14:10:22.426 16086-16086/com.example.test_01 I/D界面: onCreate
2020-07-03 14:10:22.427 16086-16086/com.example.test_01 I/D界面: onStart
2020-07-03 14:10:22.429 16086-16086/com.example.test_01 I/D界面: onResume
2020-07-03 14:10:22.855 16086-16086/com.example.test_01 I/C界面: onStop
2020-07-03 14:10:34.844 16086-16086/com.example.test_01 I/B界面: onDestroy
2020-07-03 14:10:34.876 16086-16086/com.example.test_01 I/C界面: onDestroy
2020-07-03 14:10:34.892 16086-16086/com.example.test_01 I/D界面: onPause
2020-07-03 14:10:34.908 16086-16086/com.example.test_01 I/A界面: onRestart
2020-07-03 14:10:34.908 16086-16086/com.example.test_01 I/A界面: onStart
2020-07-03 14:10:34.909 16086-16086/com.example.test_01 I/A界面: onResume
2020-07-03 14:10:35.324 16086-16086/com.example.test_01 I/D界面: onStop
2020-07-03 14:10:35.324 16086-16086/com.example.test_01 I/D界面: onDestroy
可以看出,由于A界面已经启动了一次,当再次打开A时候,会将BCD依次去销毁。只保留A界面。
A->B->C->D->A->B:
可以看见,当我创建了界面的activity,当再次去打开的时候,也是不会去再次去创建,而是重启显示出来。
本文地址:https://blog.csdn.net/qq_36771930/article/details/107100868
如对本文有疑问, 点击进行留言回复!!
网友评论