0

I am having the following issue. I have ActivityA and ActivityB. I have some radio buttons in ActivityA and the user can select them. ActivityB is accessed trough ActivityA so when I press a button I go to ActivityB. In ActivityB I do some calculations and I want to return the result to ActivityA but save the changes made in ActivityA before going to ActivityB.

If I use finish() I return to ActivityA and the selected buttons are saved but the result from ActivityB is not passed to ActivityA.

I want to know is there a way to achieve this?

2

1 Answer 1

2

Start Activity B using startActivityForResult() and pass the value from Activity B to Activity A using setResult() and retrieve that result from onActivityResult() method.

As example....

In ActivityA.java...

Intent i = new Intent(ActivityA.this, ActivityB.class); startActivityForResult(i, 1); 

In ActivityB.java...when sent your result back to ActivityA...

Intent i = new Intent(); i.putExtra("result", YourResult); setResult(1, i); finish(); 

Now, in ActivityA, retrieve the result as below...

@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode == 1) { String result = data.getStringExtra("result"); } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.