androidx.lifecycle:lifecycle-livedata-core
Official Description: Android Lifecycle LiveData Core
CommonsWare’s Notes
This artifact contains LiveData
, MutableLiveData
, and the Observer
interface used to observe LiveData
.
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, LiveData
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.
And, since 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.
However, LiveData
is not nearly as powerful as is either RxJava or Kotlin’s
coroutines (including 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 android.arch.lifecycle.LiveData
, that
is the older Architecture Components edition. androidx.lifecycle.LiveData
is the Jetpack/AndroidX edition and is the preferred choice for modern development.
Documentation
Knowledge
Samples
- InLivingColor (example of custom LiveData subclass)
- DiceLight (example of tying coroutines into LiveData)
Versions
- Latest Stable: 2.3.0
- Latest Release Candidate: 2.3.0-rc01
- Latest Beta: 2.3.0-beta01
- Latest Alpha: 2.3.0-alpha07
- 2.3.0
- 2.3.0-rc01
- 2.3.0-beta01
- 2.3.0-alpha07
- 2.3.0-alpha06
- 2.3.0-alpha05
- 2.3.0-alpha04
- 2.3.0-alpha03
- 2.3.0-alpha02
- 2.3.0-alpha01
- 2.2.0
- 2.2.0-rc03
- 2.2.0-rc02
- 2.2.0-rc01
- 2.2.0-beta01
- 2.2.0-alpha05
- 2.2.0-alpha04
- 2.2.0-alpha03
- 2.2.0-alpha02
- 2.2.0-alpha01
- 2.1.0
- 2.1.0-rc01
- 2.1.0-beta01
- 2.1.0-alpha04
- 2.1.0-alpha03
- 2.1.0-alpha02
- 2.1.0-alpha01
- 2.0.0
- 2.0.0-rc01
- 2.0.0-beta01
- 2.0.0-alpha1