I read much about issues with onActivityResult
, but it seems that none of the described problems fit to mine, like putting a negative requestCode in start
It might just be the case that your previous activity doesn't finish? Trying debugging using Log.d and view logcat to see whether the call stack actually reaches the finish() statement in your CaptureActivity class.
in my case, the scan request code must be IntentIntegrator.REQUEST_CODE,
that is
startActivityForResult(intent, IntentIntegrator.REQUEST_CODE)
.
Hope can help you.
In my case, it was not triggered since I had added flag Intent.FLAG_ACTIVITY_NEW_TASK
while creating intent for startActivityForResult
. Removing it solved my issue.
I solved the problem myself now.
After giving up to get onActivityResult
triggering, I decided to 'hack' Androids encapsulating by passing a static reference from MainActivity to CaptureActivity, even if I know that this isn't a good idea.
After the finish()
call, MAGICALLY onActivityResult
gets triggered with Context.RESULT_CANCELLED
... as expected because I don't call setResult
anymore.
Getting onActivityResult
triggered I investigated why it is working now. I found out, that it has something to do with the bitmap, passed to an Intent. If I put a Parcellable
Bitmap into my resultIntent onActivityResult
never gets fired.
So removing following line in the code above will work:
intent.putExtra(Config.SCAN_RESULT_BMP, barcode);
Thats ok for me, because I don't needed the BitMap really in this other Activity. It was more a 'feature' than a need.
If some of you guys want to pass big Data into an Intent
like a Bitmap
, think about storing it somewhere on SD, passing the path in the Intent, while reading this Bitmap
from SD in ParentActivity (How to take a photo by Intent).
As stated here, the Limit of a Parcelable
is 1MB, thus everything bigger passed to an Intent
will cause an internal TransactionTooLargeException
and will silently fail
Deleting android:noHistory="true"
from the activity I was having problem with solved the issue for me.
Make sure the number parameter (requestCode
) passed to startActivityForResult(...)
is >=0