4

Activity A started B using startActivityForResult, and B started C using startActivity. After that, the activity stack is A B C.

Now suppose, C makes startActivity call on B using FLAG_ACTIVITY_REORDER_TO_FRONT flag, then the activity stack will become A C B.

My question is, now, if B finishes itself, will onActivityResult() in A be called due to B's exiting?

Thanks.

Kai
  • 3,775
  • 10
  • 39
  • 54

1 Answers1

5

Judging by the documentation for finish():

Call this when your activity is done and should be closed. The ActivityResult is propagated back to whoever launched you via onActivityResult().

This leads me to believe that A will get B's result even if C is in between the two.

Edit - after some testing I discovered some interesting interactions here.

The order of events, after some logging:

  1. A started
  2. B started
  3. C started
  4. B resumed (with FLAG_ACTIVITY_BRING_TO_FRONT)
  5. B finished
  6. C resumed (it was under B)
  7. C finished
  8. A resumes and gets B's result

In other words, A gets B's result as expected, but it happens after C finishes and A is resumed.

Matthew
  • 44,826
  • 10
  • 98
  • 87
  • Thanks. Do you know Why C finished? There is no code that finishes C. My expected final stack status is A C. – Kai Mar 03 '11 at 22:16
  • I finished C manually. The point is that unless you finish C (or expose A somehow) A will not get B's result. – Matthew Mar 03 '11 at 22:48
  • I wonder what would happen if C started B with startActivityForResult too. Would both C and A get B's result? And does it make a difference when you call setResult in B? – Jason Hanley Mar 04 '11 at 01:09
  • Actually, FLAG_ACTIVITY_BRING_TO_FRONT doesn't change what's returned by getIntent() inside B. I had tried to have C send some data using putExtra() and no such data was found in the B that was brought to front. I'm guessing that the B will be oblivious to the requestCode/responseCode from C if it is called with FLAG_ACTIVITY_BRING_TO_FRONT – Matthew Mar 04 '11 at 03:37
  • @JasonHanley Just for future reference to anyone else out there who comes across this, tested this out, and C will NOT get B's result, even if it does call B with startActivityForResult. Only the activity that actually starts B will get the result. This results in some weird behavior, in that if you go `A->B->C->(reorder)B(finish)->C->B(finish)->C(finish)->A`, C won't get the result when B finishes the first time, but C WILL get the result code that B gives the second time, and A will get the result that B gives the first time. – David Liu Mar 09 '13 at 00:26