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

Regular code extractions

Let's take the error displaying code that we examined before:

        .observeOn(AndroidSchedulers.mainThread())        .doOnError(this::showToastErrorNotificationMethod)        .observeOn(Schedulers.io())

Since it applies a few transformations of the original Observable, we can extract a method that will apply these three actions to the original Observable, as shown:

private Observable<StockUpdate> addUiErrorHandling(Observable<StockUpdate> observable) {    return observable.observeOn(AndroidSchedulers.mainThread())            .doOnError(this::showToastErrorNotificationMethod)            .observeOn(Schedulers.io());}

Also, the modified flow will become as follows:

addUiErrorHandling(        Observable.merge(                createFinancialStockUpdateObservable(yahooService, 

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