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

Integrating with standard Java API

The simplest way to integrate any Java code into RxJava is to use the Callable interface. It's an interface that represents an operation that returns some result and can throw an exception. It's very similar to Runnable; however, Runnable interface doesn't return any value.

More information is available in the official documentation at https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Callable.html.

To make Callable a part of reactive flow, the .fromCallable() method can be used on Observable:

Observable.fromCallable(() -> someOperation());

If the operation will be long-running, you must subscribe to an Observable on a specific scheduler:

Observable.fromCallable(() -> longRunningOperation()) ...

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