Using startactivityforresult with Flags FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK

Viewed 2324

I am trying to start an activity B from activity A with intent set to Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK now i want to get back some data from Activity B to Activity A, and for that i am using startactivityforresult now the problem happening is that, when i am calling setresult from Activity B then my activity A's onactivityresult is not getting called.

Can anyone please tell me why is this happening, and if it is not possible to use startactivityforresult with (NEW_TASK and CLEAR_TASK) then what can i try instead of this.

Also I am trying to use above two intents because i want to clear my back stack when i want to open activity B.

In Activity A

Intent intent = new Intent(A.this, B.class);
Bundle args = new Bundle();
args.putString("from", "A");
intent.putExtras(args);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivityForResult(intent, 111);

On Activity B

Intent resultIntent = new Intent();
resultIntent.putExtras(data.getExtras());
setResult(Activity.RESULT_OK, resultIntent);
finish();
1 Answers

The answer to your question is simple :

the flag Intent.FLAG_ACTIVITY_NEW_TASK , is Incompatible with startActivityForResult().

So it wont work , any activity that is started by an Intent to which the flag "FLAG_ACTIVITY_NEW_TASK" was added can not return a result.

Here is the part of Android documentation that specify this.

It says :

This flag can not be used when the caller is requesting a result from the activity being launched.

Related