一.activity
1.onCreate() 创建活动,构造ui的地方,只调用一次
2.onStart() 使得活动开始显示,可以调用多次
3.onResume() 显示ui
4.onPause () 页面被隐藏或者后台运行,但没有完成退出时,调用
5.onStop() 活动停止
6.onRestart() 重新回到前台
7.onDestroy() 销毁
A->B->C->D:
A->B->C->D->A:
打印出来的各自的生命周期事件:
2020-07-03 12:02:03.060 11601-11601/com.example.test_01 I/A界面: onCreate 2020-07-03 12:02:03.061 11601-11601/com.example.test_01 I/A界面: onStart 2020-07-03 12:02:03.063 11601-11601/com.example.test_01 I/A界面: onResume 2020-07-03 12:02:08.228 11601-11601/com.example.test_01 I/A界面: onPause 2020-07-03 12:02:08.247 11601-11601/com.example.test_01 I/B界面: onCreate 2020-07-03 12:02:08.248 11601-11601/com.example.test_01 I/B界面: onStart 2020-07-03 12:02:08.250 11601-11601/com.example.test_01 I/B界面: onResume 2020-07-03 12:02:08.664 11601-11601/com.example.test_01 I/A界面: onStop 2020-07-03 12:02:09.819 11601-11601/com.example.test_01 I/B界面: onPause 2020-07-03 12:02:09.840 11601-11601/com.example.test_01 I/C界面: onCreate 2020-07-03 12:02:09.842 11601-11601/com.example.test_01 I/C界面: onStart 2020-07-03 12:02:09.843 11601-11601/com.example.test_01 I/C界面: onResume 2020-07-03 12:02:10.251 11601-11601/com.example.test_01 I/B界面: onStop 2020-07-03 12:02:11.216 11601-11601/com.example.test_01 I/C界面: onPause 2020-07-03 12:02:11.234 11601-11601/com.example.test_01 I/D界面: onCreate 2020-07-03 12:02:11.235 11601-11601/com.example.test_01 I/D界面: onStart 2020-07-03 12:02:11.237 11601-11601/com.example.test_01 I/D界面: onResume 2020-07-03 12:02:11.656 11601-11601/com.example.test_01 I/C界面: onStop 2020-07-03 12:07:36.594 11601-11601/com.example.test_01 I/D界面: onPause 2020-07-03 12:07:36.612 11601-11601/com.example.test_01 I/A界面: onCreate 2020-07-03 12:07:36.613 11601-11601/com.example.test_01 I/A界面: onStart 2020-07-03 12:07:36.615 11601-11601/com.example.test_01 I/A界面: onResume 2020-07-03 12:07:37.031 11601-11601/com.example.test_01 I/D界面: onStop
当我从A->B->C->D->A,点击返回按钮(A->D->C->B->A),事件是:
2020-07-03 12:13:57.727 11601-11601/com.example.test_01 I/A界面: onPause 2020-07-03 12:13:57.743 11601-11601/com.example.test_01 I/D界面: onRestart 2020-07-03 12:13:57.744 11601-11601/com.example.test_01 I/D界面: onStart 2020-07-03 12:13:57.745 11601-11601/com.example.test_01 I/D界面: onResume 2020-07-03 12:13:58.170 11601-11601/com.example.test_01 I/A界面: onStop 2020-07-03 12:13:58.170 11601-11601/com.example.test_01 I/A界面: onDestroy 2020-07-03 12:14:19.576 11601-11601/com.example.test_01 I/D界面: onPause 2020-07-03 12:14:19.588 11601-11601/com.example.test_01 I/C界面: onRestart 2020-07-03 12:14:19.590 11601-11601/com.example.test_01 I/C界面: onStart 2020-07-03 12:14:19.590 11601-11601/com.example.test_01 I/C界面: onResume 2020-07-03 12:14:20.001 11601-11601/com.example.test_01 I/D界面: onStop 2020-07-03 12:14:20.001 11601-11601/com.example.test_01 I/D界面: onDestroy 2020-07-03 12:14:23.023 11601-11601/com.example.test_01 I/C界面: onPause 2020-07-03 12:14:23.033 11601-11601/com.example.test_01 I/B界面: onRestart 2020-07-03 12:14:23.035 11601-11601/com.example.test_01 I/B界面: onStart 2020-07-03 12:14:23.036 11601-11601/com.example.test_01 I/B界面: onResume 2020-07-03 12:14:23.454 11601-11601/com.example.test_01 I/C界面: onStop 2020-07-03 12:14:23.454 11601-11601/com.example.test_01 I/C界面: onDestroy 2020-07-03 12:14:36.483 11601-11601/com.example.test_01 I/B界面: onPause 2020-07-03 12:14:36.494 11601-11601/com.example.test_01 I/A界面: onRestart 2020-07-03 12:14:36.496 11601-11601/com.example.test_01 I/A界面: onStart 2020-07-03 12:14:36.496 11601-11601/com.example.test_01 I/A界面: onResume 2020-07-03 12:14:36.907 11601-11601/com.example.test_01 I/B界面: onStop 2020-07-03 12:14:36.908 11601-11601/com.example.test_01 I/B界面: onDestroy 2020-07-03 12:14:41.847 11601-11601/com.example.test_01 I/A界面: onPause 2020-07-03 12:14:42.246 11601-11601/com.example.test_01 I/A界面: onStop 2020-07-03 12:14:42.246 11601-11601/com.example.test_01 I/A界面: onDestroy
二.fragment
1.onAttach() 与活动关联调用
2.onCreate() 初次创建片段
3.onCreateView() 为创建片段,返回根布局视图
4.onActivityCreated() 告诉片段,活动onCreate已经创建
5.onStart() 告诉片段可以开始显示ui
6.onResume() 显示ui
7.onPause () 页面被隐藏或者后台运行,但没有完成退出时,调用
8.onStop() 活动停止
9.onDestroyView() 允许片段可以释放资源
10.onDestroy() 允许片段清理资源
11.onDetach() 片段与活动解除关联