I have 2 Activities to explain the scenario
Activity B – Has back button and when I press the back button I go back to Activity A
@Override
public void onBackPressed() {
Intent intent = new Intent();
intent.putExtra("Title", "Sending the title back to MainActivity");
setResult(RESULT_OK, intent);
finish();
}
where I have startActivityResult() method called but its always giving me resultCode = REQUEST_CANCELLED and the intent is also null
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_PLAYBACK) {
if (resultCode == RESULT_OK) {
if (data != null && data.hasExtra("Title")) {
String text = data.getStringExtra("Title");
}
}
}
}
Its never coming into the onAcitivityResult method in Activity B
I tried few things in onBAckPressed() method
@Override
public void onBackPressed() {
Intent intent = new Intent();
intent.putExtra("Title", "Sending the title back to MainActivity");
setResult(RESULT_OK, intent);
finish();
super.onBackPressed() ------> Added this instead of finish()
}