调用 Amplify.DataStore.save() 时应用冻结
App freezes when invoking Amplify.DataStore.save()
我正在使用 Kotlin 和 AWS Amplify 制作一个简单的移动应用程序。我将首先展示我的设置。我的 schema.graphql:
type OfferGQL @model {
id: ID!
name: String!
description: String!
address: String!
price: Float!
}
我的 AWS 插件是这样设置的:
Amplify.addPlugin(AWSCognitoAuthPlugin())
Amplify.addPlugin(AWSS3StoragePlugin())
Amplify.addPlugin(AWSDataStorePlugin())
Amplify.configure(applicationContext)
这是我尝试将数据保存到 DataStore 的方式:
// Create a new offer object
val newOffer = OfferGQL.builder()
.name(textFieldOfferName.text.toString())
.description(textFieldOfferDescription.text.toString())
.address(textFieldOfferAddress.text.toString())
.price(textFieldOfferPrice.text.toString().toFloat())
.build()
// Put it in the DataStore
Amplify.DataStore.save(newOffer,
{result ->
runOnUiThread{Toast.makeText(this,"Offer added successfully", Toast.LENGTH_LONG).show()}
},
{error ->
println(error.message)
println(error.localizedMessage)
println(error.cause)
println(error.recoverySuggestion)
})
问题是,当我调用 Amplify.DataStore.save() 时,整个应用程序都冻结了。我按照文档配置了所有内容,所以我现在真的不知道为什么会这样。
在我的 phone 上完全重新安装该应用程序后,该功能终于可以使用了。
我正在使用 Kotlin 和 AWS Amplify 制作一个简单的移动应用程序。我将首先展示我的设置。我的 schema.graphql:
type OfferGQL @model {
id: ID!
name: String!
description: String!
address: String!
price: Float!
}
我的 AWS 插件是这样设置的:
Amplify.addPlugin(AWSCognitoAuthPlugin())
Amplify.addPlugin(AWSS3StoragePlugin())
Amplify.addPlugin(AWSDataStorePlugin())
Amplify.configure(applicationContext)
这是我尝试将数据保存到 DataStore 的方式:
// Create a new offer object
val newOffer = OfferGQL.builder()
.name(textFieldOfferName.text.toString())
.description(textFieldOfferDescription.text.toString())
.address(textFieldOfferAddress.text.toString())
.price(textFieldOfferPrice.text.toString().toFloat())
.build()
// Put it in the DataStore
Amplify.DataStore.save(newOffer,
{result ->
runOnUiThread{Toast.makeText(this,"Offer added successfully", Toast.LENGTH_LONG).show()}
},
{error ->
println(error.message)
println(error.localizedMessage)
println(error.cause)
println(error.recoverySuggestion)
})
问题是,当我调用 Amplify.DataStore.save() 时,整个应用程序都冻结了。我按照文档配置了所有内容,所以我现在真的不知道为什么会这样。
在我的 phone 上完全重新安装该应用程序后,该功能终于可以使用了。