【发布时间】:2019-06-03 09:30:23
【问题描述】:
我在 Room @Transaction 中的挂起功能遇到问题
版本:
room_version = "2.1.0-alpha04"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-coroutines:$room_version"
kapt "androidx.room:room-compiler:$room_version"
我也尝试使用 2.1.0-rc01。
科特林:1.3
这是我的 DAO 界面:
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(sifrBl: SifrBl)
@Query("DELETE FROM sifrbl")
suspend fun deleteAll()
@Transaction
suspend fun setSifrBl(sifrBl: SifrBl){
deleteAll()
insert(sifrBl)
}
编译时出现以下错误:
Method annotated with @Transaction must not return deferred/async return type androidx.lifecycle.LiveData. Since transactions are thread confined and Room cannot guarantee that all queries in the method implementation are performed on the same thread, only synchronous @Transaction implemented methods are allowed. If a transaction is started and a change of thread is done and waited upon then a database deadlock can occur if the additional thread attempts to perform a query. This restrictions prevents such situation from occurring.
我指的是this
如果我在所有功能中删除暂停,那么它可以工作。
任何帮助表示赞赏:)
【问题讨论】:
-
向我们展示您的依赖关系
-
不确定您要查找的依赖项。写了与 Room 和 Coroutines 相关的内容。
-
尝试将房间版本更改为
2.1.0-rc01
标签: android-room kotlin-coroutines