本系列大綱:
想要瞭解 lifecycle 在 Activity 、 Fragment 運作時的交互作用,要先從 Activity 、 Fragment 的各自功能先談起。
Activity 是 Android 應用程式的 組件 / 元件 (component)之一,其他常見的主要組件分別為 Service (服務)、Broadcast receiver (廣播接收器)、Content Provider (內容提供者)。
[圖1] Android 應用程式的主要元件們
Activity 做為應用程式(application)與使用者互動的入口點,提供應用程式在其中繪製使用者介面(User Interface, UI)的窗口。
它肩負了什麼樣的功用?
Keeping track of what the user currently cares about (what is on screen) to ensure that the system keeps running the process that is hosting the activity.
Knowing that previously used processes contain things the user may return to (stopped activities), and thus more highly prioritize keeping those processes around.
Helping the app handle having its process killed so the user can return to activities with their previous state restored.
Providing a way for apps to implement user flows between each other, and for the system to coordinate these flows. (The most classic example here being share.)
參考資料