I am trying to setResult after the BACK button was pressed. I call in onDestroy
Intent data = new Intent(); setResult(RESULT_OK, data)
But when it comes to
onActivityResult(int requestCode, int resultCode, Intent data)
the resultCode is 0 (RESULT_CANCELED) and data is 'null'.
So, how can I pass result from activity terminated by BACK button?
You need to overide the onBackPressed()
method and set the result before the call to superclass, i.e
@Override public void onBackPressed() { Bundle bundle = new Bundle(); bundle.putString(FIELD_A, mA.getText().toString()); Intent mIntent = new Intent(); mIntent.putExtras(bundle); setResult(RESULT_OK, mIntent); super.onBackPressed(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With