Kai
Kai

Reputation: 3865

FLAG_ACTIVITY_CLEAR_TOP and onActivityResult

My activity stack is A B C, with C at the top. A started B using startActivityForResult().

Now, in C, it starts A and clears the top using the following code:

        finish();

        intent = new Intent(this, A.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);

My question is, will onActivityResult() in A be called after the code above is executed? I expected it will, because B is destroyed after C starts A and clears the top. But, my test code showed that onActivityResult() in A was not called. I am confused. Can someone help?

Thanks.

Upvotes: 8

Views: 3792

Answers (2)

andysbible
andysbible

Reputation: 41

try to set the launchMode of your Activity A to the value "singleTask", or use your flag FLAG_ACTIVITY_CLEAR_TOP in conjunction with FLAG_ACTIVITY_NEW_TASK. by default, Activity A's launchMode is standard, then a new instance of A will be created when you start A from C.

Upvotes: 0

Varun
Varun

Reputation: 33983

In your code you are starting a new Activity A, from ACTIVITY C. This will not call the onActivityResult. This simply because a new Activity A is started. onActivityResult() will be called only when u finish() your Acitivity B.

I hope someone adds more to the anwsers, if this doesn make it clear.

Upvotes: 3

Related Questions