博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Activity生命周期回顾
阅读量:6705 次
发布时间:2019-06-25

本文共 3752 字,大约阅读时间需要 12 分钟。

先来一张经典的生命周期图:

 -------------------------------------------------------------

工程代码: 

--------------------------------------------------------------

1. 启动Activity 1:

08-24 17:24:51.760: D/CARLOZ-A1(20109): onCreate08-24 17:24:51.760: D/CARLOZ-A1(20109): onStart08-24 17:24:51.760: D/CARLOZ-A1(20109): onResume

1.1. 返回键 关闭Activity 1:

08-24 17:25:45.960: D/CARLOZ-A1(20109): onPause08-24 17:25:46.790: D/CARLOZ-A1(20109): onStop08-24 17:25:46.790: D/CARLOZ-A1(20109): onDestroy

1.2 HOME键回主屏,再从Recent Task中重新打开Activity1

08-24 17:26:37.610: D/CARLOZ-A1(20109): onPause08-24 17:26:38.340: D/CARLOZ-A1(20109): onStop从recent task中重新打开Activity108-24 17:26:59.380: D/CARLOZ-A1(20109): onRestart08-24 17:26:59.380: D/CARLOZ-A1(20109): onStart08-24 17:26:59.380: D/CARLOZ-A1(20109): onResume

1.3 HOME键回主屏,从Recent Task中杀死Activity1, 在从Launcher打开Activity1

08-24 17:28:06.670: D/CARLOZ-A1(20109): onPause08-24 17:28:07.450: D/CARLOZ-A1(20109): onStop08-24 17:28:15.860: D/CARLOZ-A1(22178): onCreate08-24 17:28:15.860: D/CARLOZ-A1(22178): onStart08-24 17:28:15.860: D/CARLOZ-A1(22178): onResume

 

2. 两个Activity切换

2.1 Activity1 打开Activity 2,再用返回键返回Activity1

08-24 17:32:33.150: D/CARLOZ-A1(24696): onPause08-24 17:32:33.200: D/CARLOZ-A2(24696): onCreate08-24 17:32:33.210: D/CARLOZ-A2(24696): onStart08-24 17:32:33.210: D/CARLOZ-A2(24696): onResume此时Activity2 完全覆盖Activity 108-24 17:32:33.750: D/CARLOZ-A1(24696): onStop从Activity 2 返回Activity 108-24 17:34:06.330: D/CARLOZ-A2(24696): onPause08-24 17:34:06.360: D/CARLOZ-A1(24696): onRestart08-24 17:34:06.370: D/CARLOZ-A1(24696): onStart08-24 17:34:06.370: D/CARLOZ-A1(24696): onResume08-24 17:34:06.790: D/CARLOZ-A2(24696): onStop08-24 17:34:06.790: D/CARLOZ-A2(24696): onDestroy

 

2.2 将Activity2 换成 Dialog(不能完全覆盖Activity1)

08-24 17:37:39.680: D/CARLOZ-A1(26589): onPause08-24 17:37:39.740: D/CARLOZ-A2(26589): onCreate08-24 17:37:39.740: D/CARLOZ-A2(26589): onStart08-24 17:37:39.740: D/CARLOZ-A2(26589): onResume可以看到,Activity1 不再执行onStop从Activity2返回Activity108-24 17:38:15.180: D/CARLOZ-A2(26589): onPause08-24 17:38:15.220: D/CARLOZ-A1(26589): onResume  可以看到Activity1 也不再执行onStart方法08-24 17:38:15.290: D/CARLOZ-A2(26589): onStop08-24 17:38:15.290: D/CARLOZ-A2(26589): onDestroy

2.2.1 Activity2是dialog, 点击Recent Task

08-24 17:40:42.000: D/CARLOZ-A2(26589): onPause08-24 17:40:42.010: D/CARLOZ-A1(26589): onStop08-24 17:40:42.080: D/CARLOZ-A2(26589): onStop从Recent Task状态返回08-24 17:41:24.430: D/CARLOZ-A1(26589): onRestart08-24 17:41:24.440: D/CARLOZ-A1(26589): onStart08-24 17:41:24.440: D/CARLOZ-A2(26589): onRestart08-24 17:41:24.440: D/CARLOZ-A2(26589): onStart08-24 17:41:24.440: D/CARLOZ-A2(26589): onResume

 

3. 单个Activity转屏

08-24 17:43:56.050: D/CARLOZ-A1(26589): onPause08-24 17:43:56.050: D/CARLOZ-A1(26589): onStop08-24 17:43:56.050: D/CARLOZ-A1(26589): onDestroy08-24 17:43:56.210: D/CARLOZ-A1(26589): onCreate08-24 17:43:56.210: D/CARLOZ-A1(26589): onStart08-24 17:43:56.210: D/CARLOZ-A1(26589): onResume

 

4. Activity2是Dialog的状态下转屏

08-24 17:43:11.470: D/CARLOZ-A2(26589): onPause08-24 17:43:11.470: D/CARLOZ-A2(26589): onStop08-24 17:43:11.470: D/CARLOZ-A2(26589): onDestroy08-24 17:43:11.630: D/CARLOZ-A2(26589): onCreate08-24 17:43:11.630: D/CARLOZ-A2(26589): onStart08-24 17:43:11.630: D/CARLOZ-A2(26589): onResume08-24 17:43:11.650: D/CARLOZ-A1(26589): onStop08-24 17:43:11.650: D/CARLOZ-A1(26589): onDestroy08-24 17:43:11.780: D/CARLOZ-A1(26589): onCreate08-24 17:43:11.790: D/CARLOZ-A1(26589): onStart08-24 17:43:11.800: D/CARLOZ-A1(26589): onResume08-24 17:43:11.820: D/CARLOZ-A1(26589): onPause

注意: 有Dialog主题的Activity2会导致 Activity1执行 onPause,但是纯粹的Dialog却不能触发Activity1执行onPause

 

 -------------------------------------------------------------

工程代码: 

--------------------------------------------------------------

转载地址:http://scflo.baihongyu.com/

你可能感兴趣的文章
在瀚海上的ID
查看>>
VS2013 未找到与约束ContractName Microsoft.VisualStudio.Text.ITextDocumentFactoryService
查看>>
kdbg安装使用教程(kali)
查看>>
Angular快速学习笔记(3) -- 组件与模板
查看>>
Qt读取TXT文件时,GBK与UTF-8编码判断
查看>>
南航移动Redis-Cluster趟坑记
查看>>
说说入职两日的感受
查看>>
读书笔记: CLR篇 (让你了解C#.Net的实质) (20111219更新)
查看>>
Red Hat Enterprise Linux 各版本详细说明
查看>>
解决matplotlib库在PyCharm和命令行都无法正常显示问题
查看>>
(一)Linux实操之——权限、任务调度、磁盘分区
查看>>
浅谈javascript中的作用域
查看>>
HDOJ---2577 How to Type[DP(两个DP数组)]
查看>>
Java性能总结三(转)
查看>>
Cocos2d-x for Windows Phone 8 发布
查看>>
Delphi多媒体设计之TMediaPlayer组件(七)
查看>>
生产者消费者问题理解与Java实现
查看>>
python之排序操作及heapq模块
查看>>
《设计模式》2.创建型模式
查看>>
针对于iosAPP内嵌H5,-webit-overflow-scrolling:touch;产生空白情况
查看>>