Android 谁来等待?roomdb的所有数据都准备好了

Android 谁来等待?roomdb的所有数据都准备好了,android,kotlin,Android,Kotlin,我想从room db中获取所有的门,我在Dao查询中使用实时数据,这很好,但我的应用程序并不真正需要实时数据,我想获取一次数据,它永远不会改变,所以我尝试从Dao返回列表,但有时它返回null,我尝试异步在乐趣结束时设置值,但仍然存在相同的问题 val doorList=MutableLiveData<List<Door>>() init { uiScope.launch { val doors = async(Dis

我想从room db中获取所有的门,我在Dao查询中使用实时数据,这很好,但我的应用程序并不真正需要实时数据,我想获取一次数据,它永远不会改变,所以我尝试从Dao返回列表,但有时它返回null,我尝试异步在乐趣结束时设置值,但仍然存在相同的问题

 val doorList=MutableLiveData<List<Door>>()

    init {
        uiScope.launch {

            val doors = async(Dispatchers.IO) { repository.getDoors() }


            doorList.value = doors.await()
        }
    }
val doorList=MutableLiveData()
初始化{
发射{
val doors=async(Dispatchers.IO){repository.getDoors()}
doorList.value=doors.await()
}
}

您可以使用livedata而不是mutablelivedata,请尝试更改此选项

val _doorList=MutableLiveData<List<Door>>()
val doorList = LiveData<List<Door>> get() =_doorList

    init {
        uiScope.launch {

            val doors = async(Dispatchers.IO) { repository.getDoors() }


           _doorList.value = doors.await()
        }
    }
val\u doorList=MutableLiveData()
val doorList=LiveData get()=\u doorList
初始化{
发射{
val doors=async(Dispatchers.IO){repository.getDoors()}
_doorList.value=doors.await()
}
}
希望此帮助

谢谢“希望回答问题”是zakir naik sound,错误是每填充数据未完成,并且没有aync