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

Maybe

Finally, the Maybe type is very similar to the Single type, but the item might not be returned to the subscriber in the end.

The Maybe type can be created in a very similar fashion as before:

Maybe.empty();

Alternatively, it can be created as follows:

Maybe.just("Item");

However, the .subscribe() can be called with arguments dedicated to handling onSuccess (for received items), onError (to handle errors), and onComplete (to do a final action after the item is handled):

Maybe.just("Item")        .subscribe(                s -> log("success: " + s),                throwable -> log("error"),                () -> log("onComplete")        );

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