Sign in Go Pro

RxJava

RxJava 2 - Disposing of Subscriptions with Disposable

This lesson is for PRO members.

Upgrade today to get access to all the PRO lessons.

Unlock this lesson

Previous

About

In this lesson you'll learn how to dispose of a RxJava 2 observable stream using the `Disposable` interface ([source](https://github.com/ReactiveX/RxJava/blob/2.x/src/main/java/io/reactivex/disposables/Disposable.java)). You'll be shown how to obtain a disposable instance via the `subscribe()` method overloads. The `subscribe` methods will be provided with a lambda expression that will consume the event. Since a lambda expression is used, a `LambaObservber` ([source](https://github.com/ReactiveX/RxJava/blob/2.x/src/main/java/io/reactivex/internal/observers/LambdaObserver.java)) will be returned which you can use to dispose of the observable stream. You'll also be exposed to the `subscribeWith()` operator which accepts an `Observer` instance and you'll learn how to provide a `DisposableObserver` to this method in order to properly dispose of the observable sequence. If you want to learn more about the history of the `isDisposed()` method, please see [this issue on the RxJava issues page on GitHub](https://github.com/ReactiveX/RxJava/issues/4075). This lesson is demonstrated in Kotlin. Related Lessons: - [Logging with Timber](https://caster.io/episodes/episode-14-logging-with-timber/)

Lessons in RxJava