各種常見場景下Activity的生命週期
1. Activity正常啟動:
onCreate -> onStart -> onResume
2. Activity啟動另一個Activity:
(1)B完全遮擋住A
A:onPause -> B:onCreate -> B:onStart -> B:onResume -> A:onSaveInstanceState-> A:onStop
此時如果點選Back鍵,將依次執行B:onPause -> A:onRestart -> A:onStart -> A:onResume -> B:onStop -> B:onDestroy
(2)B沒有完全遮擋住A
A:onPause -> B:onCreate -> B:onStart -> B:onResume -> A:onSaveInstanceState
此時如果點選Back鍵,將依次執行B:onPause -> A:onResume -> B:onStop -> B:onDestroy
3. 按back鍵返回到桌面
onPause -> onStop -> onDestroy
4. 按home鍵返回到桌面
onPause -> onSaveInstanceState -> onStop
5.Activity 上有 Dialog 的時候按 home 鍵返回到桌面,之後再返回到Activity
onStop -> onRestart -> onStart
6. 鎖屏再開屏
onPause -> onSaveInstanceState -> onStop -> onRestart -> onStart -> onResume
7.旋轉螢幕
onPause -> onSaveInstanceState -> onStop -> onDestroy -> onCreate -> onStart -> onRestoreInstanceState -> onResume
8.下拉狀態列
不影響Activity生命週期
Activity生命週期圖: