Ali bana
Ali bana

Reputation: 161

The result of subscribe is not used on rxjava

Hello I want ask about rxJava and Room.

here is Dao for my Room:

@Query("SELECT * from `Order` WHERE id = :ID")
fun findOrderById(ID: Int): Flowable<Order>

here is the code to call Dao:

 mDB.orderDataDao().findOrderById(orderId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe {
                    if (it.deliveryStatus == EnumOrder.IN_DELIVERY.name) {
                        mView.orderInProgress()
                        mView.setOrderFromDB(it, true)
                    } else {
                        mView.noOrderInProgress()
                        mView.setOrderFromDB(it, false)
                    }
                }

my question is why I got warning "The result of subscribe is not used on rxjava" when call Dao. why this happen and how I can make this right? I got that's warning in every code use rxJava.

Upvotes: 2

Views: 5747

Answers (2)

pixwire
pixwire

Reputation: 116

Or create CompositeDisposable in your presenter and add each disposable there. And in onDestroy() call compositeDisposable.dispose().

Upvotes: 3

PPartisan
PPartisan

Reputation: 8231

subscribe() should return a Disposable, which you can use to unregister your interest in receiving updates from your Flowable at a later point. To remove this warning, store the Disposable returned from subscribe in an instance variable, and use it with lifecycles to unsubscribe from updates. e.g.:

val disposable = mDB.orderDataDao().findOrderById(orderId).subscribe { /**/ }

//...

disposable.dispose();

Upvotes: 8

Related Questions