The following is the first few sections of a chapter from Android's Architecture Components, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
LifecycleOwner, and related classes mostly exist to provide
the foundation for
LiveData is the next generation of various
Android asynchronous solutions, such as
AsyncTask and the
LiveData, in particular, is modeled somewhat after RxJava, a popular reactive
All of this is to set up ways for you to be able to observe changes to data without having to worry as much about activity and fragment lifecycles… though, as it turns out, you cannot escape them entirely.
The observer pattern in software design has been around for decades. Yet, it has caught fire in the past few years, repackaged as “reactive programming”. Reactive programming visualizes an app as a set of streams of data changes, whether from the user (e.g., UI widget interactions), from a server (e.g., updates to data from a sync operation), or from something else (e.g., GPS fixes). Developers set up observers to respond (“react”) to these data changes and apply updates to the UI.
The centerpiece for reactive programming in Android is RxJava, typically combined with RxAndroid. RxJava provides the basic framework for observing streams of data changes, with RxAndroid primarily providing ways to route results of observations to the main application thread. This book is not going to go into details of how you use RxJava/RxAndroid in general — for that, see The Busy Coder’s Guide to Android Development or other books.
One problem with RxJava, though, is that “it is difficult to get your head wrapped around it”. Reactive programming works great in platforms that implemented reactive programming from the outset. Reactive programming is more difficult to bolt onto an existing platform, both from a technical standpoint and from a documentation standpoint. RxJava is the sort of technology that is easy to illustrate in “hello, world”-level examples but gets difficult to explain for more practical scenarios. In part, that is because RxJava is extremely flexible, and with great flexibility comes great need for great documentation… which RxJava historically lacked.
LiveData is designed to be a much lighter-weight approach to reactive programming,
designed to do one thing (deliver asynchronous data changes regardless of lifecycle
events) and do it reasonably well.
The preview of this section was eaten by a grue.
The preview of this section was last seen in the Bermuda Triangle.
The preview of this section left for Hollywood to appear in a reality TV show.