Data streams
When it comes to data observability, we have multiple approaches for implementation, whether manually built mechanisms, components from the Java language, third-party components, or finally to solutions developed particularly for Android. When it comes to Android, some of the most common solutions are LiveData
, Flows from the Coroutines components, and RxJava.
The first one we will look at is LiveData
, as it is part of the Android Architecture Components, which means that it is tailored specially to Android. We will then look at how we can use other types of data streams, which we will cover in more depth in future chapters.
LiveData
LiveData
is a lifecycle-aware component that permits updates to your UI, but only if the UI is in an active state (for example, if the activity or fragment is in one of the STARTED
or RESUMED
states). To monitor changes on LiveData
, you need an observer combined with a LifecycleOwner
. When the activity is set to an active state, the...