In my App a certain result code is used to finish the whole App when this is needed (i.e to finish all Activities which belongs to my App in the Activity stack). All Activities are started with startActivityForResult(). The result code is captured in onActivityResult() and is from there passed on to the next Activity in the Activity stack. This boils down to each Activity finishing itself when the certain result code is being used.
Works great.. in all cases except for one:
Consider an Activity stack consisting of A -> B -> A. The last A (right in the sequence) starts the procedure by finishing itself and setting the result code for finishing the other Activities as well. After B has finished and passed on the result code to the first A (left A in the sequence) it turns out onActivityResult() is not called.
It can be worth mentioning that onDestroy() has not yet been called for the topmost A in the stack (right A in the sequence) when the first A is reached.
How to fix or work round this issue?
It turned out this issue only appeared if the Activity was started from the menu written with the following code:
Here are the string resources
Simply add this code to the base Activity in the code sample from inazaruk to see for yourself. Toggle between Activity A and Activity B a couple of times through the menu, and then try to close all Actitvities in the stack. It will not work.
Now one would think the cause was the intent flag:
However adding this flag to all intents in the code from inazaruk excludes this.
If anyone can explain exactly what happens it would be great to hear.