I have two activities: a MainListActivity, and a DetailViewActivity. DetailViewActivity is set with android:launchMode="singleTop".
When clicking an item in the “main list” activity, it launches the “detail view” activity via:
startActivityForResult(detailIntent, REQUEST_CODE_DETAIL);
If I then call setResult(RESULT_OK, resultData); and finish(); from within the Detail activity, that resultData is received by the “main list” activity’s onActivityResult(..) method correctly.
However, if I implement a “see previous”/”see next” type of navigation within the Detail activity, and implement it using singleTop, that result no longer gets sent back to the initial activity:
Intent nextItemIntent = this.createIntent(nextId);
nextItemIntent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
startActivity(nextItemIntent);
// at this point, my DetailActivity's onNewIntent() method is called, and the new data is loaded properly
But from here, when I call setResult(..) and finish(), my MainList activity never receives the new/updated result.
Anyone know what I’m doing wrong?
Bah… my mistake. Looks like the problem was
FLAG_ACTIVITY_FORWARD_RESULT. Apparently that flag is not needed when usingFLAG_ACTIVITY_SINGLE_TOPandonNewIntent(..).. So by settingFLAG_ACTIVITY_FORWARD_RESULT, I was actually telling Android to forward my result data one activity farther back on the stack (activity before MainListActivity).I removed that flag, and it now works as expected:
And all is well.