O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Converting RxJava 1.0 Observables

We will quickly see that it is super easy to convert Observables from the old interface to the new one.

First of all, let's create an old-typed Observable that we can play with, something like this:

rx.Observable.just("One", "Two", "Three")        .doOnNext(i -> log("doOnNext", i))        .subscribe(i -> log("subscribe", i));

To convert that to a new Observable of the io.reactivex.Observable type, we will need to use RxJavaInterop.toV2Observabe():

RxJavaInterop.toV2Observable(rx.Observable.just("One", "Two", "Three"))        .doOnNext(i -> log("doOnNext", i))        .subscribe(i -> log("subscribe", i));

It worth noting that it is especially useful to use the static import in such cases so that the code can be simplified to the following: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required