Official Description: Android Lifecycle LiveData Core
This artifact contains
MutableLiveData, and the
interface used to observe
LiveData is a lightweight data holder with a lifecycle-aware observer
system. Observers, when registered, are given the existing value in the
LiveData (if there is one), plus any updates to the value while the observer
remains registered. Since observers are (usually) tied to lifecycles,
can automatically remove observers when their associated lifecycles are destroyed.
This eliminates the need to manually unregister these observers.
The resulting API is reactive: observers respond to data updates as they occur.
LiveData is designed for use by Android UIs, observers are notified
on the main application thread, even if the data was updated on a background thread.
LiveData is not nearly as powerful as is either RxJava or Kotlin’s
Flow). A popular pattern is to use one of those other
reactive frameworks for much of the work, then use
LiveData for the “last mile”
delivery of data to activities and fragments.
As with many pieces of the Jetpack,
LiveData was available before the Jetpack
was defined. If you see references to
is the older Architecture Components edition.
is the Jetpack/AndroidX edition and is the preferred choice for modern development.
- InLivingColor (example of custom LiveData subclass)
- DiceLight (example of tying coroutines into LiveData)
- Latest Stable: 2.2.0
- Latest Release Candidate: 2.2.0-rc03
- Latest Beta: 2.2.0-beta01
- Latest Alpha: 2.3.0-alpha03