Member-only story
Exploring Android LiveData Usages and Behaviors
Simple app to demonstrate Android lifecycle-aware LiveData usages and behaviors — setValue(), postValue(), observe(), and observeAsState().
6 min readNov 11, 2022
This is part of the asynchronous flow series:
- Part 1 — Exploring Android LiveData Usages and Behaviors
- Part 2 — Introduction to Kotlin Flows and Channels
- Part 3 — Exploring Different Ways to Collect Kotlin Flow
- Part 4 — Convert Flow to SharedFlow and StateFlow
- Part 5 — Flow, SharedFlow, StateFlow Class Diagram
- Part 6 — Kotlin Flow — Combine, Merge and Zip
Android LiveData
is observable and lifecycle-aware data.
Assuming the lifecycle owner is an activity, lifecycle-aware means it will only send updates to the UI when the activity is active. Activity is active means the UI is visible either in the background (started state) or in the foreground (resumed state).
LiveData
also automatically removes all Observer
objects when the activity is destroyed.