Activity A 启动 Activity B 生命周期

Activity A启动 B:

A.onPaunse - B.onCreate - B.onStart - B.onResume - A.onstop

2021-02-26 16:26:34.578 2754-2754/? I/MICO.base: [main] Activity onPause Launcher
2021-02-26 16:26:34.599 2754-2754/? D/MICO.base: [main] Activity onCreate SettingsActivity, , taskId: 17
2021-02-26 16:26:34.643 2754-2754/? D/MICO.base: [main] SettingsActivity onCreate
2021-02-26 16:26:34.650 2754-2754/? I/MICO.base: [main] Activity onStart SettingsActivity
2021-02-26 16:26:34.651 2754-2754/? I/MICO.base: [main] Activity onResume SettingsActivity
2021-02-26 16:26:35.032 2754-2754/? D/MICO.base: [main] Fragment onStop RefrigeratorMainFragment540
2021-02-26 16:26:35.032 2754-2754/? I/MICO.base: [main] Activity onStop Launcher

从B返回A:

B.onPause - A.onRestart - A.onStart - A.onResume - B.onStop - B.onDestory

2021-02-26 17:22:18.574 2754-2754/? I/MICO.base: [main] Activity onPause SettingsActivity
2021-02-26 17:22:18.596 2754-2754/? I/MICO.base: [main] Activity onRestart Launcher
2021-02-26 17:22:18.602 2754-2754/? D/MICO.base: [main] Fragment onStart RefrigeratorMainFragment540
2021-02-26 17:22:18.603 2754-2754/? I/MICO.base: [main] Activity onStart Launcher
2021-02-26 17:22:18.605 2754-2754/? I/MICO.base: [main] Activity onResume Launcher
2021-02-26 17:22:18.611 2754-2754/? I/MICO.base: [main] Fragment onActivate RefrigeratorMainFragment540
2021-02-26 17:22:18.612 2754-2754/? D/MICO.base: [main] Fragment onResume RefrigeratorMainFragment540
2021-02-26 17:22:18.718 2754-2754/? I/MICO.base: [main] Activity onStop SettingsActivity
2021-02-26 17:22:18.721 2754-2754/? D/MICO.base: [main] Activity onDestroy SettingsActivity 
2021-02-26 17:22:18.723 2754-2754/? D/MICO.base: [main] SettingsActivity onDestroy

在这里插入图片描述
我们可以在源码里面,可以看到注释已经写的很清楚了,B 创建成功之后,才会调用A的onStop

特殊情况:

如果B 是个透明的,或者是对话框的样式, 就不会调用A 的onStop()方法。因为对用户来说,A 还是可见的。

为什么要这样设计? 从源码怎么看?

当一个页面,还没有创建出来,不应该在后台,只是暂停,所以A onPasue 就去创建B. B创建成功后,就调用A.onStop。

参考:
https://www.jianshu.com/p/5dcfea447d0f

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页