blinkid-android icon indicating copy to clipboard operation
blinkid-android copied to clipboard

Exception after calling recognizerBundle.loadFromIntent(intent)

Open smsibtainrn opened this issue 5 months ago • 3 comments

          Caused by java.lang.IllegalStateException: Expected intent transferable object does not exist in the intent!
       at com.microblink.intent.BaseIntentTransferable.loadFromIntent(line:18)
       at ae.gov.adnoc.ui.members.ocrPreview.view.OcrPreviewActivity.onActivityResult(OcrPreviewActivity.kt:236)
       at android.app.Activity.onActivityResult(Activity.java:7737)
       at android.app.Activity.internalDispatchActivityResult(Activity.java:9784)
       at android.app.Activity.dispatchActivityResult(Activity.java:9761)
       at android.app.ActivityThread.deliverResults(ActivityThread.java:6567)
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:5901)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:6007)
       at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:57)
       at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:60)
       at android.app.servertransaction.TransactionExecutor.executeLifecycleItem(TransactionExecutor.java:225)
       at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:107)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:81)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2895)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loopOnce(Looper.java:257)
       at android.os.Looper.loop(Looper.java:342)
       at android.app.ActivityThread.main(ActivityThread.java:9634)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:619)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:929)
        

smsibtainrn avatar Nov 14 '25 05:11 smsibtainrn

Hello,

Thank you for sharing the stack trace. To help us further investigate the issue, could you please provide the following details:

  1. Intent data transfer mode you are using (STANDARD, OPTIMISED, PERSISTED_OPTIMISED)
  2. Code snippet showing how you initialize the SDK
  3. Code snippet where loadFromIntent is used
  4. SDK version you are currently using

PatrikKap avatar Nov 14 '25 16:11 PatrikKap

Hello Patrik,

  1. Using PERSISTED_OPTIMISED
  2. initialize

try { MicroblinkSDK.setLicenseKey(AdnocUtils.blinkCard(BuildConfig.flavor), this) com.microblink.MicroblinkSDK.setLicenseKey(AdnocUtils.blinkId(BuildConfig.flavor), this) MicroblinkSDK.setIntentDataTransferMode(IntentDataTransferMode.PERSISTED_OPTIMISED) MicroblinkSDK.setShowTrialLicenseWarning(false) com.microblink.MicroblinkSDK.setShowTrialLicenseWarning(false) } catch (e: Exception) { isRecognitionSupported = false }

  1. *loadFromIntent *

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (resultCode == Activity.RESULT_OK) { when(requestCode){ MY_BLINK_ID_REQUEST_CODE -> { if (data != null) { mRecognizerBundle.loadFromIntent(data) val result = mRecognizer.result if (result.resultState == Recognizer.Result.State.Valid) { proceedResult(result) } } } }else { onBackPressed() } }

  1. Using versions, * @.') @.*')

Thanks and regards, Sibtain Raza

On Fri, Nov 14, 2025 at 9:34 PM Patrik @.***> wrote:

PatrikKap left a comment (BlinkID/blinkid-android#352) https://github.com/BlinkID/blinkid-android/issues/352#issuecomment-3533596388

Hello,

Thank you for sharing the stack trace. To help us further investigate the issue, could you please provide the following details:

  1. Intent data transfer mode you are using (STANDARD, OPTIMISED, PERSISTED_OPTIMISED)
  2. Code snippet showing how you initialize the SDK
  3. Code snippet where loadFromIntent is used
  4. SDK version you are currently using

— Reply to this email directly, view it on GitHub https://github.com/BlinkID/blinkid-android/issues/352#issuecomment-3533596388, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACZKT52C6OI6M4VPATJ6BNL34YAABAVCNFSM6AAAAACMCRTM4GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTKMZTGU4TMMZYHA . You are receiving this because you authored the thread.Message ID: @.***>

smsibtainrn avatar Nov 17 '25 04:11 smsibtainrn

Hello Sibtain,

The issue you’re encountering looks like it’s caused by loading the RecognizerBundle from the Intent multiple times, particularly after the app has been restarted.

When using PERSISTED_OPTIMISED mode, the Recognizer objects are passed via an internal singleton and also serialized into a file in your app’s private folder. If Android restarts your app and the singleton is empty, the data will be loaded from the file automatically. However, if the app is restarted multiple times, only the first restart will succeed. Subsequent loads will fail unless you explicitly save the bundle state

To prevent this issue, please implement onSaveInstanceState() and save the RecognizerBundle to file using its saveState() method. After saving, make sure to clear the saved state in onResume(), since onCreate() may not be called if the activity isn’t restarted, while onSaveInstanceState() can be triggered when the activity goes to the background (before onStop), even though activity may not be killed at later time.

Once you try this out, please let us know if your issue is resolved.

Kind regards, Patrik

PatrikKap avatar Nov 17 '25 12:11 PatrikKap