I have 2 Activities, A and B.
A invokes B with an intent and request code –
startActivityForResult(i,123);
… later I want A to stop B and then itself, so in A I did
finishActivity(123);
finish(); // finish itself
… but B doesn’t stop! BUT if I set breakpoints at all the onStop’s and onDestroy’s and step through in the debugger everything works perfectly and both Activities go away. (this suggests a timing or race condition)
However if I comment-out A’s finish() …
finishActivity(123);
// finish(); // finish itself
B does finish but A doesn’t because its finish has been taken away. What is the correct way to have one activity finish another one that it created, and then finish itself?
Thanks in advance.
See if this works:
The reason I suggest this is that I think the call to
finish()is not givingfinishActivity(123)a chance to do its thing. By callingrunOnUiThread, the call tofinish()will take place on the next loop through the UI message queue.