不推荐使用onActivityResult如何发送startResolutionForResult

所以我使用 gps 类来打开 gps,这是一种允许我们发送到的方法onActivityResult,但由于在 AndroidX 上已弃用并且仍然可用,android 团队向我们推荐下一个:

强烈推荐使用AndroidX中引入的Activity Result APIs

我有以下代码,我尝试发送到 onActivityResult

val rae = e as ResolvableApiException
rae.startResolutionForResult(context,Constants.GPS_REQUEST)

如何使用新 API 处理相同的事情?

回答

我在 Kotlin 中所做的是:

registerForActivityResult(StartIntentSenderForResult()) { result ->
    if (result.resultCode == RESULT_OK) {
        // Your logic
    }
}.launch(IntentSenderRequest.Builder(rae.resolution).build())

原答案:https : //stackoverflow.com/a/65943223/4625681


以上是不推荐使用onActivityResult如何发送startResolutionForResult的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>