Android Convert Room LiveData Async to Sync

October 21, 2018

You have to create two methods if you need both sync and async behaviour

  • return LiveData<List<Pin>> for async
  • return List<Pin> for sync
interface PinDao : BaseDao<Pin> {
    @Query("SELECT * FROM pin WHERE is_active = 1 ORDER BY created DESC")
    fun fetchAll(): LiveData<List<Pin>>

    @Query("SELECT * FROM pin WHERE is_active = 1 ORDER BY created DESC")
    fun fetchAllSync(): List<Pin>
}
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.