RxLifecycle allows you to automatically unsubscribe from observable sequences when an Activity or Fragment is destroyed.
Unlike other libraries, RxLifecycle actually performs the unsubscription, meaning downstream observers will no longer receive onComplete() or onError() once unsubscription occurs. It does not require you to inherit from specific base classes; instead, it inserts a non-GUI fragment to monitor lifecycle events.
Important: To ensure that the downstream does not continue to emit items after the lifecycle event, you must place the .compose(RxLifecycle.bind(...)) call at the bottom of your observable chain.
Observable.interval(0, 2, TimeUnit.SECONDS)
// ...
.compose(RxLifecycle.bind(this)
.<Long>disposeObservableWhen(LifecycleEvent.DESTROY_VIEW))
.subscribe();