Room - LiveData observer does not trigger when database is updated

前端 未结 2 1231
Happy的楠姐
Happy的楠姐 2020-12-03 10:39

I am trying to find out in the code below, why is it that Room\'s LiveData observable does not give me new shifts once I populate the database with new data.

This is

2条回答
  •  执笔经年
    2020-12-03 11:10

    I had a similar problem using Dagger 2 that was caused by having different instances of the Dao, one for updating/inserting data, and a different instance providing the LiveData for observing. Once I configured Dagger to manage a singleton instance of the Dao, then I could insert data in the background (in my case in a Service) while observing LiveData in my Activity - and the onChange() callback would be called.

    It comes down to the instance of the Dao must be the same instance that is inserting/updating data and providing LiveData for observation.

提交回复
热议问题