I'm using AWS Amplify v2.3.0 on Android Studio. Looking AWS documentation I can use Kotlin-Callback or Kotlin-Coroutines code. The callbacks call works for me. But the coroutines not working because IDE tell me that needs more parameters.
I need to use coroutines and not callbacks.For example, the sample AWS Code with callbacks works form me:
private fun getTodo(id: String) {
Amplify.API.query(ModelQuery.get(Todo::class.java, id),
{ Log.i("MyAmplifyApp", "Query results = ${(it.data as Todo).name}") },
{ Log.e("MyAmplifyApp", "Query failed", it) }
);
}
But the coroutine AWS sample code not works, because query function needs more parameters.
suspend fun getTodo(id: String) {
try {
val response = Amplify.API.query(ModelQuery.get(Todo::class.java, id))
Log.i("MyAmplifyApp", response.data.name)
} catch (error: ApiException) {
Log.e("MyAmplifyApp", "Query failed", error)
}
}
Anyone know what is happening?
Thank you so much!
Use the AWS SDK for Kotlin to write Android Apps. The AWS SDK for Kotlin supports Coroutines. See this doc topic in the Kotlin DEV Guide:
https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/coroutines.html
Using this SDK, you can invoke AWS services from an Android project. For details, see this Android example in the AWS Code Library that shows you how to create an Android app that invokes AWS Services in an Android Studio project:
https://docs.aws.amazon.com/code-library/latest/ug/cross_SnsPublishSubscription_kotlin_1_topic.html
See: