I am trying to send data from child activity to parent. But somehow, onActivityResult(..) is not getting called. here is code
Parent activity
selecte
Use singleTop instead of singleInstace as launchMode as it maintains the activity in the same task.
onPause was effecting onActivityResult.
One of the corner case might be:
my case was different and silly: The problem was in onPause, finish
called and end the activity. Removed that and works well.
@Override
protected void onPause() {
super.onPause();
finish(); // this line causing the issue removed it.
}
I found the mistake. I had below line in manifest.xml for child acitivity.
android:launchMode="singleInstance"
after removing this line. it's working like a charm!!!
Thank You all for your input and suggestions.
Not sure if this is your case, but when starting the child activity make sure you use startActivityForResult(intent)
, instead of startActivity();
For anyone stuck with same problem, a symptom not to receive onActivityResult
, following cases can cause this issue.
startActivityForResult()
correctly, do not use startActivity()
.onBackPressed
method, super.onBackPressed();
has to be positioned at the last of the method, not at the first line. (my case to spend 5 hours)android:launchMode="singleInstance"
in manifest or equivalent argument to create a intent.noHistory="true"
in manifest of the callee activity.setResult()
is missed.finish()
is called to close the activity. use finishActivity()
to close callee activity.requestCode
more than zero. negative value does not work.My case was a little bit complex and I realized that I used by error a static reference pointing to the first instance of the buttons listeners in a sub activity.
At the first turn it was working, but when the user was returning from the parent activity, onActivityResult
was not called.
Replacing the static references was the fix