Android onActivityResult not called / triggered

后端 未结 8 2429
醉梦人生
醉梦人生 2020-12-05 04:41

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

8条回答
  •  时光取名叫无心
    2020-12-05 05:05

    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

提交回复
热议问题