user485498
user485498

Reputation:

Sending data back and forth between two Activities in Android

I have an Activity ActivityA say. From ActivityA I start ActivityB using an Intent, sending some string data to the new activity. ActivityA gets pushed into the background, not destroyed.

Intent newActivity = new Intent(this, ActivityB.class);
newActivity.putExtras("SomeString", "important data");
startActivity(newactivity);

Now I want to manipulate the string data and send it back to AcitivtyA. Not a new instance of ActivityA, but the instance that has been paused. I am unsure how to do this. ANy help is appreciated.

Upvotes: 1

Views: 1859

Answers (2)

Robby Pond
Robby Pond

Reputation: 73484

You need to start B with startActivityForResult() and override onActvityResult() in A. Before you finish B you will need to call setResult() to set the data you want to send back to A.

Read the section of Starting Activities in the documentation.

Upvotes: 2

providence
providence

Reputation: 29463

Try using start activity for result. See here

Upvotes: 0

Related Questions