Ravi Bhandari
Ravi Bhandari

Reputation: 4698

Returning from StartActivityForResult opening Same Activity

I am not sure what the problem in my code, today i face an strange problem when calling startActivityForResult.

Below is my code -

From Activity A when i call -

startActivityForResult(intent,122);

Then Activity B opens as desire. Now while i am calling below line of code from activity B -

 Intent in = getIntent();
 setResult(Activity.RESULT_OK,in);
 finish();

Then its open same Activity B.

I debugged code and found that onCreate() of Activity B called when i am finishing activity B.

Any one can sort out this problem much appreciated.

TIA

Upvotes: 1

Views: 1368

Answers (2)

Saurabh Vardani
Saurabh Vardani

Reputation: 1861

Do like this...

 Intent i = new Intent(ActivityB.this, ActivityA.class);
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                setResult(RESULT_OK, i);
                finish();

Upvotes: 3

Mehta
Mehta

Reputation: 1226

Try below code in Activity B:

Intent intent = new Intent();
setResult(requestCode, intent);
finish();

Upvotes: 2

Related Questions