Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass argument to previous activity

Tags:

android

I would like to pass arguments from an activity B to A where B has been launched by A. Is this possible to do so ? Thanks

like image 991
Swan Avatar asked Dec 03 '22 02:12

Swan


1 Answers

Yes, if when you launch Activity B from A, you start it using startActivityForResult then you can set a result in Activity B then read the value in A.

In A you would need to override onActivityResult to get the result value.

In Activity B:

// do stuff
setResult(RESULT_OK);
finish();

Then in A:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    //check result
}
like image 71
dave.c Avatar answered Jan 01 '23 14:01

dave.c