Android Jetpack: How to smartly use fragments in your UI
summary
Architecture Components reposition fragments as UI-policy containers rather than grab‑all objects: use ViewModel + LiveData for retained data, replace headless retained fragments, and prefer the Navigation component to manage back stack and animations so you avoid manual async fragment transactions (use commitNow only when safe). Fragment inflation and DialogFragment remain useful for self‑contained screens, ads or important prompts. android.app.Fragment is deprecated; rely on AndroidX fragments and the new lifecycle guarantees for predictable behavior.
AI-written summary · about
chapters (16)
- 0:00Origins of fragments
- 2:04Design and legacy
- 4:40Decomposing activities
- 7:34State management challenges
- 10:03Architecture components
- 12:35Lifecycle and observers
- 15:54View models vs fragments
- 18:56Live data usage
- 21:31Fragment transactions
- 24:19Navigation component
- 27:38Role of fragments today
- 30:43Content-based fragments
- 33:47Dialog fragments
- 37:15Menu and toolbar management
- 39:34Testing and modernization
- 42:06Future and deprecation
related talks
30mFragments: What are they good for.
18mFragments: The good (non-deprecated) parts
37mWhat To Do About Fragments? (en)
46mModern Android: How to ditch Activities and Fragments
38mAndroid Architecture Components
56mYou've been told lies about Fragments
33mFear No Fragments
47mArchitecting your Android app with Jetpack
