therealbluepandabear
05/13/2022, 8:19 AMvar toReturn: PixelArt? = null
CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>).launch {
AppData.pixelArtDB.pixelArtCreationsDao().getAllPixelArtCreations().observe(this@extendedGetCurrentPixelArtObj.findViewTreeLifecycleOwner()!!) {
toReturn = it[currentIndex]
}
}
return toReturn!!
bezrukov
05/13/2022, 8:35 AMdao.liveDataQuery().asFlow().first()
BUT, you use Room, which natively supports coroutines, so you can simply switch from LiveData
to Flow
, or to simply suspend
functiontherealbluepandabear
05/13/2022, 8:44 AMMarcello Galhardo
05/13/2022, 8:55 AMFlow
. There is no need to return a LiveData
simple to convert it to a Flow
.
Google has a CodeLab that teaches you how to use Room and Flow. Check Respond to data changes using Flow.therealbluepandabear
05/13/2022, 12:28 PMAdam Powell
05/13/2022, 1:46 PM