So simply, the DAO
@Query("DELETE FROM Things WHERE someIdOfTheThing IN (:listOfId)")
abstract fun deleteThings(listOfId: MutableList<String>): Maybe<Int>
usage,
mDisposables.add(mThingsDao
.deleteThings(listOfId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
...
}, {
...
})
)
and error,
// Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
The simple idea i was thinking is to specify subscribeOn(Schedulers.io())
and then give all the job to Rx's magical hands, but failed.
So what's the thing i'm missing ?
After wrapping like below and using deleteThingsWrapped
, started working. But still don't understand why first approach not worked
open fun deleteThingsWrapped(listOfId: MutableList<String>): Maybe<Int> {
return Maybe.create(object : MaybeOnSubscribe<Int> {
override fun subscribe(emitter: MaybeEmitter<Int>) {
emitter.onSuccess(deleteThings(listOfId))
}
})
}
@Query("DELETE FROM Things WHERE someIdOfTheThing IN (:listOfId)")
abstract fun deleteThings(listOfId: MutableList<String>): Maybe<Int>
.subscribe
– Groovy