Updated 5 July 2017


RxJava is a Java VM implementation of ReactiveX (Reactive Extensions): a library for composing asynchronous and event-based programs by using observable sequences.

The build blocks for RxJava code are the following:

  • observables representing sources of data
  • subscribers (or observers) listening to the observables
  • a set of methods for modifying and composing the data

Add dependency for Rx java in build.gradle.

Observable just produces an Observable that emits a single generic instance. For example:

Create an instance of Observer to get the data from the data source (Observable). The data source push data to onNext() method in the observer.

Once the observable instance initialised subscribe the observer.

OUTPUT:  hello world

 Advantages of RxJava

Some advantages of RxJava are the following:

  • You can chain async operations, e.g., if a API call depends on the call of another API
  • A defined way to handle errors
  • It reduces the need for state variables, which can be the source of errors == Creating sources, subscribing to them and disposing them
. . .

Leave a Comment

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

Be the first to comment.

Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home