我正在使用以下代码发布我的房间查询结果
_data.postValue(databaseImpl.findRepoById(id).value)
但似乎返回的对象是空的。我猜我们需要观察 databaseImpl.findRepoById(id),而不是直接访问它,但由于它在视图模型中,我没有生命周期所有者分配给房间查询 livedata。
databaseImpl.observe(this, Observer { //!!this is modelview and not activity
_data.postValue()
})
使用 Room 查询和更新中介实时数据的正确方法是什么?