I wasn't sure wether to post here or in
#android, but the issue I'm having is with the Kotlin coroutines library. Just need some help getting my head around what I'm doing wrong!
# MainActivity.kt
override fun onStart() {
super.onStart()
var applicationID = runBlocking { Application.registerDevice() }
Log.d("AppID on-start", applicationID)
}
# Application.kt
object Application {
suspend fun registerDevice(): String {
return getTokenAsync().await()
}
private suspend fun getTokenAsync(): kotlinx.coroutines.Deferred<String> = coroutineScope {
async {
return@async FirebaseInstallations.getInstance().id.result.toString()
}
}
}
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.application, PID: 20890
java.lang.IllegalStateException: Task is not yet complete
If anyone could see where I'm going wrong and help point me in the right direction on what I can do to resolve this I would really appreciate it 🙂
Thanks in advance!