I am calling activityB from activityA and passing a class object using intent.
Intent intentB = new Intent(v.getContext(), activityB.class);
intentB.putExtra("data", data); //data is a class object
startActivity(intentB);
The activityB starts fine and also I am able to extract data. In activityB, I am modifying the data object. I want to send this modified data object back to activityA when activityB.onDestroy() is called.
Any advice?
Here is my code:
activityA, starting the Intent
:
Intent i = new Intent(this, activityB.class);
i.putExtra("object", Class.object);
startActivityForResult(i, 1);
activityA, catching the intent:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
object = data.getParcelableExtra("object"); //the Class implements Parcelable
}
}
activityB
protected void onDestroy() {
Intent data = new Intent();
setResult(RESULT_OK, data)
finish(); // ends current activity
}
Make use of the ActivityResult.
startActivityForResult(int, Intent)
setResult(RESULT_OK, data)
(where data is an Intent)onActivityResult(int, int, Intent)
and catch the data
-IntentActivity A, starting the Intent
:
Intent i = new Intent(this, SecondActivity.class);
startActivityForResult(i, 1);
Activity A, catching the data:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
// make use of "data" = profit
}
}
Activity B:
Intent data = new Intent();
setResult(RESULT_OK, data)
finish(); // ends current activity
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