Fragment lifecycle phức tạp hơn Activity: onAttach(), onCreate(), onCreateView(), onViewCreated(), onStart(), onResume(), onPause(), onStop(), onDestroyView(), onDestroy(), onDetach().
- Điểm khác biệt quan trọng là View của Fragment có thể bị destroy (
onDestroyView) trong khi Fragment vẫn còn trong bộ nhớ. - Vì vậy phải dọn dẹp View references trong
onDestroyView()để tránh memory leak.