我正在尝试使用 Room 数据库和 LiveData。我有 ViewModel,其中包含他们从 dao 获得的 LiveData。如果我更新 a Transaction
,则LiveData<List<Transaction>>
可以观察到,但LiveData<Transaction>
根本没有观察到。这怎么可能?我究竟做错了什么?
public abstract class Dao {
@Query("SELECT * FROM transact WHERE deleted = :value")
public abstract LiveData<List<Transaction>> allTransactions(boolean value);
@Query("SELECT * FROM transact WHERE guid = :guid AND deleted = :value ")
public abstract LiveData<Transaction> getTransaction(String guid, boolean value);
@Update(onConflict = OnConflictStrategy.REPLACE)
protected abstract void updateTransaction(Transaction transaction);
}
有类似的问题,它提到了使用非@Singleton
注释类时的 Dagger 并发症,不幸的是,这不是我的问题,即使我使用 Dagger。