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

Informing the user about the failure

We should also briefly mention how to handle notifications when we are unable to read remote financial stock data.

As we saw in the section dedicated to error handling, a good approach would be to show a Toast notification. So, to inform the user, we will just reuse the code we created before:

.doOnError(error -> {    Toast.makeText(this, "We couldn't reach internet - falling back to local data",            Toast.LENGTH_SHORT)            .show();})

In a larger context of the flow, this will look as shown:

.flatMap(        i -> Observable.<YahooStockResult>error(new RuntimeException("Crash"))).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).doOnError(error -> {    Toast.makeText(this, "We couldn't reach internet ...

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