RxJava Android Tutorials

In this series of posts i will be covering RxJava which can used in android for asynchronous work. It extends the observer pattern to support sequences of data/events and adds operators that allow you to compose sequences together declaratively while abstracting away concerns about things like low-level threading, synchronization, thread-safety and concurrent data structures.

This diagram shows how function is applied on data which is emitted by Observable.

How to Design Using RxJava

To use RxJava you create Observables (which emit data items), transform those Observables in various ways to get the precise data items that interest you (by using Observable operators), and then observe and react to these sequences of interesting items (by implementing Observers or Subscribers and then subscribing them to the resulting transformed Observables).

A subscriber can get 3 major events :

  • onNext() : Called when data after some transformation comes to subscriber.
  • onError() : Some error occurred while processing.
  • onCompleted() : When data emission is completed.

Adding dependency to build.gradle file

RxJava can be added to android application by simply adding gradle dependency.

Since we will be using this on android so we have to add dependency of RxAndroid in gradle file.

Final module level build.gradle should contain highlighted lines.

Thats all you need to add for to use RxJava in your application. Lets now explore examples .

Examples for RxJava :

  1. Adding lambdas support to Android Studio
  2. Use RxJava instead of AsyncTask Android
  3. Using RxBinding instead TextWatcher on EditText
  4. Using RxJava with Retrofit2

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *