The Simplest RxJava Observable Sample App

ADA | Adam Deconstructs Android

Adam Hurwitz
AndroidPub
2 min readMay 16, 2016

--

The RxJava Observable pattern in Android Development is excellent for handling multiple complex tasks and allowing control of how processes and data are handled. It’s hard to say if this is going to be a best practice or just this year’s trend, however it does seem to have current benefits.

The Two Main Advantages

  1. Run tasks concurrently rather than linearly
  2. Ease of use threading between background and main threads

The best way to learn something new in Android is to find a minimal viable example that showcases the concept at it’s most basic level, trace through the classes and methods to understand how it works, tinker and customize to further understand, and then lastly building something on your own.

I haven’t seen many sample repo apps I can Pull, de-construct, and play around with so I made a straightforward sample app using the .from() and .map() Operators that passes in an ArrayList and transforms the attributes of the ArrayList Objects based on the Switch in the UI.

YES, you might be asking why I did not simply use a For Loop here to iterate through the ArrayList Objects and you are certainly correct for asking that. What if you wanted to process multiple Lists at the same time and needed the data at the same exact point in time? This pattern would come in handy for that. Also, if what you are processing is not essential to any UI components you can simply send it to a background thread to save the app from stalling. Assuming the scenario where the attributes are not being showcased in the UI, you’d want to transform the attributes on a background thread to free up any UI interactions in a more sophisticated app.

Sam Chordas, part of the team @ Udacity created a more complete example of how Observables can be used to make network calls which I highly recommend.

Resources

Here’s a few places to continue reading up on Observables in greater detail. Also, a search in Medium for RxJava Android will provide a host of in-depth posts.

Fundamentals

Examples

Other Stuff

--

--

Adam Hurwitz
AndroidPub

An account about nothing | Researcher and product consultant