I'm using RxJava Flowable with Room
where I listen to changes in a table. The problem as mentioned is that when the result of subscribe, a disposable, is added to a CompositeDisposable, it immediately unsubscribes
.
Below is the relevant code :
repo.getFlowable(id)
?.doOnDispose { Timber.i("Unsubscribed") }
?.doOnDispose { Timber.i("Disposed") }
?.subscribe({
Timber.i("Subscribed")
}, {
Timber.e(it)
})?.apply {
compositeDisposables.add(this)
}
When the apply block is added, "Unsubscribed" and "disposed" are printed immediately even though "compositeDisposables.dispose()" is not called.
Without the apply block, it is working as expected.
Is this an expected behaviour? Why does the subscription gets disposed immediately when the Composite Disposable is not disposed yet?