I've upgraded to Android Studio 3.1 today, which seems to have added a few more lint checks. One of these lint checks is for one-shot RxJava2 subscribe()
calls that are not stored in a variable. For example, getting a list of all players from my Room database:
Single.just(db)
.subscribeOn(Schedulers.io())
.subscribe(db -> db.playerDao().getAll());
Results in a big yellow block and this tooltip:
The result of
subscribe
is not used
What is the best practice for one-shot Rx calls like this? Should I keep hold of the Disposable
and dispose()
on complete? Or should I just @SuppressLint
and move on?
This only seems to affect RxJava2 (io.reactivex
), RxJava (rx
) does not have this lint.
Disposable
at member scope and callingdispose()
when the single completes, but it seems needlessly cumbersome. I'm interested to see if there's any better ways of doing this. – Rustication