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

Using CompositeDisposable

The approach of manually tracking each Subscription might become unwieldy if there are multiple Subscriptions that need to be tracked in the same Activity. In this case, a CompositeDisposable might come in very handy. It's a class that can keep references to multiple Disposables and then unsubscribes from all of them at the same time.

So, consider this case:

Disposable disposable1 = Observable.interval(1, TimeUnit.SECONDS)        .subscribe();Disposable disposable2 = Observable.interval(1, TimeUnit.SECONDS)        .subscribe();Disposable disposable3 = Observable.interval(1, TimeUnit.SECONDS)        .subscribe();

Here, we have three Disposables that we would normally need to unsubscribe from with three calls to .dispose(). By introducing ...

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