I'm trying to write a function in Kotlin that needs to return a Bitmap
after getting a stream from a StorageReference
object. Since I can't use a solution that implements listeners I have to define a Continuation
and get the result when the StreamDownloadTask
is completed.
The following is my not working attempt
fun getAdImg(imgId: String): Bitmap? {
return storage.child(FOLDER).child(imgId+EXTENSION).stream.continueWith(Continuation<StreamDownloadTask.TaskSnapshot, Bitmap>() {
return BitmapFactory.decodeStream(it.result)
})
}
I cannot understand how to define the Continuation
object as there are no examples anywhere using basic types. I guess I have to override the then
function and check if the Task
has been completed in order to fetch the result.
EDIT1: The error says:
Type mismatch. Required: Bitmap? Found: Task<Bitmap!>