The following is the first few sections of a chapter from Exploring Android, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
Let’s take a closer look at the data flow that we are trying to implement here, as part of our Model-View-Intent architecture:
Figure 181: MVI Flow Diagram
The terms used in the diagram are from the architecture pattern. Sometimes, those do not reflect the actual classes that are serving in those roles:
View, but rather our fragments
RosterViewModel, named to be aligned with the Architecture Components
ToDoModel) and their repository (
We have only two more nouns to implement. Chief among those is the “Controller”,
which is responsible for responding to actions published by the “View” and, among
other things, updating our “Model” in response. Since we have no particular ties
to other names for this class, we can call our “Controller”
We need to have the
Controller respond to actions published by the fragments.
The way that we will do that pulls in another popular library: RxJava. RxJava
ushered in the era of reactive programming in Android, despite it being a pure
Java library, not tied directly to Android at all. We will have our fragments
publish actions using an RxJava
Observable type, which represents a stream
of events. The
Controller will subscribe to that stream on a background thread
and process those events.
This is a continuation of the work we did in the previous tutorial. The book’s GitHub repository contains the results of the previous tutorial as well as the results of completing the work in this tutorial.
RxJava has a GitHub repository that has a lot of documentation. However, bear in mind that there are two major generations of RxJava: RxJava 1.x and RxJava 2.x. We are using the newer 2.x generation. The RxJava GitHub repository sometimes blurs the line between these generations, so be careful.
Some introductory material on RxJava can be found in a chapter in The Busy Coder’s Guide to Android Development.
Also, a lot has been written about RxJava and its use in Android. However, due to the aforementioned pair of RxJava generations, focus on material written in 2017 onwards. 2016 material that specifically mentions RxJava 2 is also fine. Older material will refer to RxJava 1, and while the concepts are the same, any specific instructions will be incorrect, due to changes in the way that RxJava works.
The preview of this section was eaten by a grue.
The preview of this section was lost due to a rupture in the space-time continuum.
The preview of this section was traded for a bag of magic beans.
The preview of this section is unavailable right now, but if you leave your name and number at the sound of the tone, it might get back to you (BEEEEEEEEEEEEP!).
The preview of this section is presently indisposed.
The preview of this section is in an invisible, microscopic font.
The preview of this section is out seeking fame and fortune as the Dread Pirate Roberts.
The preview of this section is in the process of being translated from its native Klingon.
The preview of this section will not appear here for a while, due to a time machine mishap.