4

I am confused about Room and can not find an answer in the documentation.

So, the library enforces using queries on a separate Thread, which is understandable. However, it seems that Delete queries are not included in this limitation and can be freely called from the UI Thread. They also always return a raw output value, without a chance to wrap it in an Observable.

What is the correct way to use the delete call in Room then? Should it be run on a separate Thread? If not, what about performance and concurrent modifications?

Kelevandos
  • 7,024
  • 2
  • 29
  • 46

1 Answers1

5

If you use LiveData to retrieve data from Room, it's executed in worker thread. For, other queries you can use Executors and Repository pattern. You can check out this page for guide to app architecture.

You can check out this link for Rx and other architecture component samples.


Analysis note by the question author:

In the sample they use a Completable to wrap the Room delete call and then schedule it onto the io() scheduler, reacting to the empty complete and any errors. That specific code can be found here.

Kelevandos
  • 7,024
  • 2
  • 29
  • 46
Thracian
  • 43,021
  • 16
  • 133
  • 222
  • I have a repository pattern, based on Rx (no LiveData and no real chance to refactor into it). Should I then wrap the delete calls into Singles and subscribe them on a background Thread? If so, why doesn't Room's Rx integration offer Single returns on deletes in the first place? – Kelevandos Jul 17 '18 at 12:04
  • I don't use Rx, you can check out these [tutorials](https://github.com/googlesamples/android-architecture-components/) for detailed usage. – Thracian Jul 17 '18 at 12:29
  • Amazing, this is exactly what I needed! :-D Please update the answer with this link, so I can accept it as correct. Thanks! – Kelevandos Jul 17 '18 at 12:33
  • 1
    I added a small note with the roundup of the code under the link you provided and also accepted the answer. Thanks again! – Kelevandos Jul 17 '18 at 16:07
  • It's good to have that note. I will check it out again after i learnt RxJava. Thanks also. – Thracian Jul 17 '18 at 16:21