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

Single

Single provides a way to represent an Observable that will return just a single item (thus the name). You might ask, why it is worth having it at all? These types are useful to tell the developers about the specific behavior that they should expect.

To create a Single, one can use this example:

Single.just("One item")

The Single and the Subscription to it can be created with the following:

Single.just("One item")        .subscribe((item) -> {            log(item);        }, (throwable) -> {            log(throwable);        });

Note that this differs from Completable in that the first argument to the .subscribe() action now expects to receive an item as a result.

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