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

Versions