Activity lifecycle có 6 method chính theo thứ tự: onCreate() (khởi tạo), onStart() (trở nên visible), onResume() (có focus), onPause() (mất focus), onStop() (không còn visible), onDestroy() (dọn dẹp).
- Hiểu lifecycle rất quan trọng vì bạn phải lưu state trong
onSaveInstanceState()và khôi phục trongonCreate(). - Memory leak thường xảy ra khi giữ strong reference đến Activity quá vòng đời của nó.
Activity lifecycle has six main methods: onCreate() (initialize), onStart() (become visible), onResume() (gain focus), onPause() (lose focus), onStop() (not visible), onDestroy() (cleanup).
- Understanding this is critical because you must save state in
onSaveInstanceState()and restore it inonCreate(). - Memory leaks often occur if you hold strong references to activities beyond their lifecycle.