androidgpsandroidxdeprecatedonactivityresult

onActivityResult is deprecated how do I send startResolutionForResult


So I'm using a gps class to turn on the gps and here's a method that allow us to send to onActivityResult, but since is deprecated on AndroidX and still available, android team recommend us the next:

it is strongly recommended to use the Activity Result APIs introduced in AndroidX

I have a the following code where I try to send to onActivityResult

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

How do I approach the same thing with the new API?


Solution

  • What I did in Kotlin was:

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

    Original answer: https://stackoverflow.com/a/65943223/4625681