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?
activity:activity-ktx to 1.2. 0 . It has deprecated startActivityForResult in favour of registerForActivityResult . It was one of the first fundamentals that any Android developer has learned, and the backbone of Android's way of communicating between two components.
But recently startActivityForResult() method is deprecated in AndroidX. Android came up with ActivityResultCallback (also called Activity Results API) as an alternative for it. Step 1: You just have to create an ActivityResultLauncher and pass following parameters handle onActivityResult in it as shown above.
you are right, onActivityResult() is getting called before onResume().
registerForActivityResult() takes an ActivityResultContract and an ActivityResultCallback and returns an ActivityResultLauncher which you'll use to launch the other activity. An ActivityResultContract defines the input type needed to produce a result along with the output type of the result.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With