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

Fixes for duplicate entries

Earlier, we introduced a mechanism to skip duplicate entries from the financial stock updates that rely on .groupBy(). However, now it won't work because the distinctUntilChanged() block will get destroyed each time the .switchMap() block receives a new value and thus the last received entry will be lost.

The fix is quite simple. Consider this code:

.groupBy(stockUpdate -> stockUpdate.getStockSymbol()).flatMap(groupObservable -> groupObservable.distinctUntilChanged())

It has to be moved outside the .merge():

Observable.merge(...)        .groupBy(stockUpdate -> stockUpdate.getStockSymbol())        .flatMap(groupObservable ->         groupObservable.distinctUntilChanged())        .compose(bindUntilEvent(ActivityEvent.DESTROY)) .subscribeOn(Schedulers.io()) ...

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