如果房间数据库中的某些内容发生了变化,Kotlin Flow是否每次都会发出新数据?
假设这里是示例代码
livedata查询
Query("SELECT IFNULL(COUNT(id),0) FROM Item WHERE status = :status")
fun getLiveData(status: Int): LiveData<Int>
kotlin流量查询
@Query("SELECT IFNULL(COUNT(id),0) FROM Item WHERE status = :status")
fun getFlowData(status: Int): Flow<Int>
,我的问题是,如果房间数据库中有任何变化,则流程会获取新数据?
Let's Say Here is Sample Code
LiveData Query
Query("SELECT IFNULL(COUNT(id),0) FROM Item WHERE status = :status")
fun getLiveData(status: Int): LiveData<Int>
Kotlin Flow Query
@Query("SELECT IFNULL(COUNT(id),0) FROM Item WHERE status = :status")
fun getFlowData(status: Int): Flow<Int>
So my Question is Flow gets new data if anything changes in the room database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,如果房间数据库中有任何变化,则流量会发出新数据,例如以下示例:
还有
.first()
,它将仅向您提供没有实时更改的最新发射数据:因此,它取决于您的使用方式如何,这取决于您的需求。
Yes Flow emits new data if anything changes in the room database, like the example below:
and also there is
.first()
that will give you only the latest emitted data without live changes:So it depends on how you are using Flow, and it depends on your needs.