Android onActivityResult not called / triggered

后端 未结 8 2406
醉梦人生
醉梦人生 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 04:58

    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.

    0 讨论(0)
  • 2020-12-05 04:59

    in my case, the scan request code must be IntentIntegrator.REQUEST_CODE,

    that is

    startActivityForResult(intent, IntentIntegrator.REQUEST_CODE).

    Hope can help you.

    0 讨论(0)
  • 2020-12-05 05:03

    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.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-05 05:08

    Deleting android:noHistory="true" from the activity I was having problem with solved the issue for me.

    0 讨论(0)
  • 2020-12-05 05:13

    Make sure the number parameter (requestCode) passed to startActivityForResult(...) is >=0

    0 讨论(0)
提交回复
热议问题