onActivityResult method not being called Android
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.
For anyone stuck with same problem, a symptom not to receive onActivityResult
, following cases can cause this issue.
- check you are using
startActivityForResult()
correctly, do not usestartActivity()
. - if you do something in overriden
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) - remove
android:launchMode="singleInstance"
in manifest or equivalent argument to create a intent. - remove
noHistory="true"
in manifest of the callee activity. - check
setResult()
is missed. finish()
is called to close the activity. usefinishActivity()
to close callee activity.- use
requestCode
more than zero. negative value does not work.
Not sure if this is your case, but when starting the child activity make sure you use startActivityForResult(intent)
, instead of startActivity();
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