Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 223
Barrufet Avatar asked Dec 15 '20 08:12

Barrufet


People also ask

What can I use instead of startActivityForResult in Android?

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.

What can I use instead of Startactivity for results?

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.

What is called after onActivityResult?

you are right, onActivityResult() is getting called before onResume().

How do I use registerForActivityResult?

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.


1 Answers

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

like image 62
Dhananjay Suresh Avatar answered Oct 05 '22 07:10

Dhananjay Suresh