We haven’t used Otto [an Android-focused event bus library] in a year and a half, if not more...We think we found a better mechanism. That mechanism is...RxJava where we can create a much more specific pipeline of events than a giant generic bus that just shoves any event across it.
RxJava is a powerful library. There are many situations where RxJava provides a cleaner, more flexible way of implementing a feature within our Android apps. In this chapter, I try to show why you should consider using RxJava in your Android code.
First, I show that RxJava can load asynchronous data in a way that is both efficient and safe, even in cases where the data is loaded into objects whose lifecycle we do not control (e.g.,
Fragments, etc.). Second, I compare an RxJava-based implementation of a search feature for our example HackerNews client app to a solution based on
Handlers, and Listeners and I try to say a little about the advantages of the RxJava-based solution.
We do not have complete control over the lifecycle of the
Activitys within our apps. Ultimately, the Android framework is responsible for creating and destroying
Activitys. If the user rotates a device, for example, the
Activity that is currently on screen may be destroyed and re-created to load the layout appropriate for the device’s new orientation.
This feature of the Android framework requires any effective asynchronous ...