Android Convert Room LiveData Async to Sync

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>}

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.