Activity แทนหน้าจอเดียวที่มีส่วนติดต่อผู้ใช้ ซึ่งเป็นองค์ประกอบพื้นฐานของ Android การเข้าใจ lifecycle ของมัน (ลำดับของสถานะและ callback ขณะที่ถูกสร้าง แสดง ซ่อน และทำลาย) เป็นเรื่องสำคัญอย่างยิ่งต่อการจัดการทรัพยากรและสถานะให้ถูกต้อง
Activity คืออะไร
An ACTIVITY = one screen of the app (a UI the user interacts with):
→ an app is typically several activities (a login screen, a home screen, etc.)
→ the OS manages activities and calls LIFECYCLE methods as their state changes
Activity lifecycle
Key lifecycle callbacks (the OS calls these as the activity's state changes):
onCreate() → activity is being CREATED → initialize UI, set up (called once)
onStart() → becoming VISIBLE to the user
onResume() → now in the FOREGROUND, interactive (user can interact)
onPause() → losing focus (another activity coming in front) → pause/save lightly
onStop() → no longer VISIBLE → release resources, stop heavy work
onDestroy() → being DESTROYED → final cleanup
→ Flow: onCreate → onStart → onResume → [running] → onPause → onStop → onDestroy
