Fragment는 UI의 재사용 가능한 조각이며, 다양한 화면 크기에 유연하게 대응하기 위해 도입되었습니다. 🧩
FragmentManager는 Fragment의 추가, 제거 등 Fragment 관리를 담당하며, 상황에 따라 supportFragmentManager, parentFragmentManager, childFragmentManager를 사용합니다. 🧰
Fragment 트랜잭션은 beginTransaction으로 시작하여 add, replace, remove 등의 작업 후 commit으로 완료해야 적용됩니다. 🎬
Fragment 생명 주기는 Activity와 유사하며, onAttach, onCreate, onCreateView, onViewCreated, onStart, onResume, onPause, onStop, onDestroyView, onDestroy, onDetach 등의 콜백을 가집니다. 🔄
onDestroyView에서 뷰 참조를 null로 설정하여 메모리 누수를 방지하고, 기본 생성자를 유지하거나 FragmentFactory를 사용하여 Fragment 재생성 오류를 방지해야 합니다. ⚠️