Threads and Room
@Insert
, @Update
, and @Delete
-annotated methods are synchronous, performing their work on the current thread. Hence, they should only be called from a background thread.
@Query
methods that return entities, int
, tuples, etc. directly also are synchronous. However, @Query
methods that return an RxJava type (e.g., Flowable
) or a LiveData
are not synchronous. Instead, the real work will be performed on a background thread.
As noted earlier, we will explore what this “LiveData
” is later in the book. For now, take it on faith that it is another piece of the Android Architecture Components, one that offers an alternative to RxJava for reactive programming.
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.