Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get original request data (intent extras) in onActivityResult callback?

Tags:

android

Curious, if I can invoke some 3rd party activity, and then in onActivityResult read my original intent data.

like image 230
alex2k8 Avatar asked Jun 20 '10 02:06

alex2k8


People also ask

How do I get my data back from activity?

To access the returned data in the calling Activity override onActivityResult . The requestCode corresponds to the integer passed in the startActivityForResult call, while the resultCode and data Intent are returned from the child Activity.

Which method is used to call another activity when we expect to get something back from the called activity?

onPause() and then onStop() methods will call when you change the activity ,,if you finish the current activity while moving to the second activity the onDestory() also called..

Can startActivityForResult still be used?

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.

Is startActivityForResult deprecated?

onActivityResult , startActivityForResult , requestPermissions , and onRequestPermissionsResult are deprecated on androidx.


1 Answers

I does not make any sence for me, really... Anyway, as the onActivityResult will be always part of the same Activity that launched the 3rd party activity you just have to save that data somewhere on your activity. For instance:

private Intent intentForThat3rdPartyActivity = null; // long name, huh?

public void hereYouLaunchThings(){
    if( intentForThat3rdPartyActivity == null ){
        intentForThat3rdPartyActivity = new Intent(YourActitity.this, The3rdPartyActivity.class);
        intentForThat3rdPartyActivity.putExtra("weird", "data");
    }
    startActivityForResult(intentForThat3rdPartyActivity, 9999);
}

@Override
protected void onActivityResult(int requestCode, int resultCode,
                                 Intent data) {
    // this should have the same data you passed
    String foo = intentForThat3rdPartyActivity.getStringExtra("weird");
}
like image 62
Cristian Avatar answered Sep 29 '22 17:09

Cristian