How to Survive the Lifecicle
summary
Android X adds a third lifecycle — the viewLifecycleOwner — to fix stale UI and observer leaks when fragments detach and reattach. Use LiveData + ViewModel for retained state, observe use‑case streams with the fragment lifecycle and observe view state with viewLifecycleOwner in onViewCreated, or pass the lifecycle into reusable views / data binding. A concrete Kotlin pattern builds custom view composition that registers observers on attach and auto‑removes them on destroy, eliminating boilerplate and memory leaks.
AI-written summary · about
chapters (10)
- 0:00Introduction to lifecycle
- 3:07LiveData and ViewModel basics
- 8:27Fragment rotation case
- 9:28Fragment backstack issue
- 13:01View lifecycle owner solution
- 14:28Three abstraction levels
- 17:17Simple app architecture
- 18:42Navigation and use cases
- 21:16Composition over inheritance
- 24:46Summary and Q&A
related talks
28mLifecycle, LiveData, ViewModels - The inner wiring
23mLifecycle, LiveData, Viewmodels - The inner wiring
41mViewModels, LiveData and Lifecycles, oh my!
28mInternals of Android Architecture Components
45mAndroid Architecture Components Considered Harmful
23mMaster of Lifecycle
47mAndroid Architecture Component
30mSurviving a discontinuous world
