Activity生命周期:onCreate onStart onResume onStop onRestart onPause onDestory
Activity启动生命周期:
onCreate
onStart
onResume
ActivityA--->ActivityB--->B finish
2020-07-25 20:41:21.351 4996-4996/com.example.basepro E/tag: A-onCreate
2020-07-25 20:41:21.356 4996-4996/com.example.basepro E/tag: A-onStart
2020-07-25 20:41:21.358 4996-4996/com.example.basepro E/tag: A-onResume
2020-07-25 20:41:24.530 4996-4996/com.example.basepro E/tag: A-onPause
2020-07-25 20:41:24.573 4996-4996/com.example.basepro E/tag: B-onCreate
2020-07-25 20:41:24.584 4996-4996/com.example.basepro E/tag: B-onStart
2020-07-25 20:41:24.591 4996-4996/com.example.basepro E/tag: B-onResume
2020-07-25 20:41:25.156 4996-4996/com.example.basepro E/tag: A-onStop
2020-07-25 20:41:31.807 4996-4996/com.example.basepro E/tag: B-onPause
2020-07-25 20:41:31.819 4996-4996/com.example.basepro E/tag: A-onRestart
2020-07-25 20:41:31.819 4996-4996/com.example.basepro E/tag: A-onStart
2020-07-25 20:41:31.819 4996-4996/com.example.basepro E/tag: A-onResume
2020-07-25 20:41:32.387 4996-4996/com.example.basepro E/tag: B-onStop
2020-07-25 20:41:32.388 4996-4996/com.example.basepro E/tag: B-onDestroy
ActivityA--->ActivityB(窗口activity或者透明activity)--->B finish
A还是可见的所以不会走onStop B finish的时候 ,A不会走onRestart onStart,直接走onResume获取焦点
2020-07-25 20:43:25.706 5147-5147/com.example.basepro E/tag: A-onCreate
2020-07-25 20:43:25.710 5147-5147/com.example.basepro E/tag: A-onStart
2020-07-25 20:43:25.712 5147-5147/com.example.basepro E/tag: A-onResume
2020-07-25 20:43:28.412 5147-5147/com.example.basepro E/tag: A-onPause
2020-07-25 20:43:28.454 5147-5147/com.example.basepro E/tag: B-onCreate
2020-07-25 20:43:28.461 5147-5147/com.example.basepro E/tag: B-onStart
2020-07-25 20:43:28.463 5147-5147/com.example.basepro E/tag: B-onResume
2020-07-25 20:43:58.129 5147-5147/com.example.basepro E/tag: B-onPause
2020-07-25 20:43:58.154 5147-5147/com.example.basepro E/tag: A-onResume
2020-07-25 20:43:58.161 5147-5147/com.example.basepro E/tag: B-onStop
2020-07-25 20:43:58.177 5147-5147/com.example.basepro E/tag: B-onDestroy
ActivityA--->ActivityB--->C-->A
A launchMode=singleTask
2020-07-25 20:52:16.648 5627-5627/com.example.basepro E/tag: A-onNewIntent
2020-07-25 20:52:16.648 5627-5627/com.example.basepro E/tag: A-onRestart
2020-07-25 20:52:16.649 5627-5627/com.example.basepro E/tag: A-onStart
A不会走onCreate ,走onNewIntent
系统可能会随时杀掉后台运行的 Activity ,如果这一切发生,那么系统就会调用 onCreate 方法,而不调用 onNewIntent 方法,一个好的解决方法就是在 onCreate 和 onNewIntent 方法中调用同一个处理数据的方法
A launchMode=singleTop(A在栈顶和singleTask一样,如果不再栈顶 还会走onCreate)
如何主题设置了<item name="android:windowIsTranslucent">true</item> 会引起A生命周期走2次 设置为false可解决