Fun with LiveData
summary
LiveData is lifecycle-aware and a single-value holder that delivers only the latest value to active observers, not a stream, so use it for UI state but not for event streams or large JSON blobs. It demonstrates concrete tools: map, switchMap and MediatorLiveData, and a custom aggregate (a totalLength mediator implemented in about four lines of code) that sums multiple LiveData strings. Beware sharing a singleton LiveData across activities (causes visible flash during transitions). For heavy reactive chains or one‑shot work prefer RxJava or coroutines; samples and a GitHub browser / I/O app are provided.
AI-written summary · about
chapters (9)
- 0:00Introduction to LiveData
- 2:00Lifecycle awareness
- 3:55Data holder property
- 5:27Transformations with Map
- 7:58Switch Map and custom logic
- 9:36Customizing LiveData
- 12:02Common mistakes and patterns
- 14:00Correct wiring patterns
- 16:50When not to use LiveData
related talks
28mLifecycle, LiveData, ViewModels - The inner wiring
41mLiveData beyond VIewModels
23mLifecycle, LiveData, Viewmodels - The inner wiring
41mViewModels, LiveData and Lifecycles, oh my!
38mMigrating from LiveData to Coroutines and Flow
48mHow do LiveData and Coroutines actually work
39mSimple MVI: A LiveData Based MVI Approach
33mJUnit 5 Testing: Android Unidirectional Data Flow with LiveData
