It’s funny how we spent about an hour trying to figure out why the Intent extras that we’re setting are not being sent back to onActivityResult()
. If we only knew that the solution was as simple as moving one line of code.
The call to super.onBackPressed()
should be placed after setting Intent extras and after finishing the current activity. Like so:
1 2 3 4 5 6 7 8 9 10 |
@Override public void onBackPressed() { Intent intent = new Intent(CurrentActivity.this, MainActivity.class); intent.putExtra("myData", "success"); setResult(RESULT_OK, intent); finish(); super.onBackPressed(); } |