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.

RxJava and Room

In a previous chapter, we saw how a Room DAO could return a LiveData object as a wrapper around the “real” data to be retrieved from the database. Then, the @Query method would no longer be a blocking call, but instead would return the LiveData immediately, with the actual query results being delivered to any observers of the LiveData.

Not surprisingly, you can do the same thing with RxJava types. Simply wrap the return type from the @Query method in a suitable RxJava type. You get the same results as you do with LiveData: the @Query method returns the RxJava object immediately, and you get the actual query results via RxJava’s subscriber system.

However, RxJava is a much richer library, and it is commensurately more complex. In this chapter, we will explore what RxJava types can be returned by a @Query, how those work with respect to data changes, and how the underlying data type affects all of that.

Adding RxJava

RxJava has its own dependencies. In an Android app, typically you will use io.reactivex.rxjava2:rxjava and io.reactivex.rxjava2:rxandroid, where the latter provides utility classes like AndroidSchedulers.

However, Room itself does not have a transitive dependency upon RxJava. Otherwise, everybody using Room would need to pull in RxJava, and that would add unnecessary bloat.

So, in addition to the regular dependencies for RxJava and the regular dependencies for Room (e.g.,, you also need the dependency. This contains the glue code necessary to tie Room to RxJava:

  implementation ""
  implementation ""
  annotationProcessor ""

If you forget this dependency, but you have the regular RxJava and Room dependencies, you will not notice a problem right away. You will be able to use RxJava types in your DAO, because Android Studio knows about RxJava through your existing dependencies. However, when you go to build and run the project, your build will fail with:

Error:(41, 24) error: To use RxJava2 features, you must add `rxjava2` artifact from Room as a dependency.<version>

Decisions, Decisions

The preview of this section is en route to Mars.

The One-Time Option: Single

The preview of this section is in an invisible, microscopic font.

The One-Time 0-1 Option: Maybe

The preview of this section is out seeking fame and fortune as the Dread Pirate Roberts.

The Ongoing Option: Flowable

The preview of this section is in the process of being translated from its native Klingon.

@RawQuery and Reactive Responses

The preview of this section is presently indisposed.