'Is it possible to use LiveData directly when requesting ROOM?

Trying to try mvvm and livedata, I have a query in the database Room

@Query("SELECT * FROM User ")
fun getAllUsers(): LiveData<MutableList<User>>

@Query("SELECT * FROM User ")
fun getAllUsersRx(): Flowable<MutableList<User>> 

I call the methods from the ViewModel and everything comes in both cases, but if everything works in another thread via rx, then in the case of LiveData everything should happen in mainThread. But then why doesn’t Room give the error IllegalStateException: Cannot access the database on the main thread? And is it correct in this case to directly request data from Room using LiveData, or do I need to transfer the operation to another thread by myself?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source