ViewModels, LiveData and Lifecycles, oh my!
summary
Practical demo of Android Architecture Components: uses ViewModel + LiveData + Lifecycle to move UI state out of Activities (example: Court Counter) so data survives rotations via ViewModelProvider and retained fragments, shows MutableLiveData vs LiveData with setValue/postValue, uses Transformations.map for formatting and switchMap to swap underlying LiveData for a search app backed by a repository (Room suggested). Notes ViewModel dies on process-kill and recommends saving minimal keys in savedInstanceState and persisting heavier data in a database.
AI-written summary · about
chapters (12)
- 0:00Introduction to architecture
- 4:27Redesigning Court Counter
- 10:45ViewModel lifecycle explained
- 15:40Passing values to ViewModel
- 16:03LiveData lifecycle awareness
- 19:34Transforming LiveData with map
- 23:50LiveData recap and MutableLiveData
- 25:15Introducing repository pattern
- 27:20Naive search implementation
- 29:27Using switchMap for searches
- 35:25Recap of repository and LiveData
- 35:47Persisting UI state after process death
related talks
47mAndroid Architecture Component
28mLifecycle, LiveData, ViewModels - The inner wiring
42mArchitecture Components: A Better Path Forward (Lifecycle & Live Data)
30mClean App Design with Architecture Components
44mAndroid Architecture Components, a New Way to Build Apps
47mClean app design with Architecture Components
28mInternals of Android Architecture Components
23mLifecycle, LiveData, Viewmodels - The inner wiring
