ZebraDevs / DataWedge-Flutter-Demo

Demo application to show basic barcode capture in Flutter apps using DataWedge on Zebra devices
MIT License
59 stars 30 forks source link

Missing unregisterReceiver function #14

Open mjablecnik opened 2 years ago

mjablecnik commented 2 years ago

Hello, when I quit your demo application so this error exception is showed:

E/ActivityThread( 5050): Activity com.darryncampbell.datawedgeflutter.MainActivity has leaked IntentReceiver com.darryncampbell.datawedgeflutter.MainActivity$createDataWedgeBroadcastReceiver$1@547c660 that was originally registered here. Are you missing a call to unregisterReceiver()?
E/ActivityThread( 5050): android.app.IntentReceiverLeaked: Activity com.darryncampbell.datawedgeflutter.MainActivity has leaked IntentReceiver com.darryncampbell.datawedgeflutter.MainActivity$createDataWedgeBroadcastReceiver$1@547c660 that was originally registered here. Are you missing a call to unregisterReceiver()?
E/ActivityThread( 5050):    at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:1351)
E/ActivityThread( 5050):    at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1132)
E/ActivityThread( 5050):    at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1421)
E/ActivityThread( 5050):    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1394)
E/ActivityThread( 5050):    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1382)
E/ActivityThread( 5050):    at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:609)
E/ActivityThread( 5050):    at com.darryncampbell.datawedgeflutter.MainActivity$configureFlutterEngine$1.onListen(MainActivity.kt:38)
E/ActivityThread( 5050):    at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler.onListen(EventChannel.java:188)
E/ActivityThread( 5050):    at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler.onMessage(EventChannel.java:167)
E/ActivityThread( 5050):    at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:84)
E/ActivityThread( 5050):    at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:865)
E/ActivityThread( 5050):    at android.os.MessageQueue.nativePollOnce(Native Method)
E/ActivityThread( 5050):    at android.os.MessageQueue.next(MessageQueue.java:325)
E/ActivityThread( 5050):    at android.os.Looper.loop(Looper.java:142)
E/ActivityThread( 5050):    at android.app.ActivityThread.main(ActivityThread.java:6494)
E/ActivityThread( 5050):    at java.lang.reflect.Method.invoke(Native Method)
E/ActivityThread( 5050):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
E/ActivityThread( 5050):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

I understand that there is somewhere missing unregisterReceiver() function which is called for unregister dataWedge. How can I prevent this error?

darryncampbell commented 2 years ago

Can you call onCancel to unregister the receiver? https://github.com/ZebraDevs/DataWedge-Flutter-Demo/blob/master/datawedge_flutter/android/app/src/main/kotlin/com/darryncampbell/datawedgeflutter/MainActivity.kt#L42 Sorry, it has been a while since I looked at the code.

mjablecnik commented 2 years ago

Thank you for your so quick answer. Yes I know about onCancel function in Kotlin code but I don't know how can I call it correctly from Dart code. If you can update this Flutter demo, it would be very helpful for me..

mjablecnik commented 2 years ago

I am trying call something like this: image

But it doesn't solve it.

darryncampbell commented 2 years ago

Unfortunately I am not able to work on this project right now but I suggest you do the following:

This plugin / sample is released under MIT so there are no restrictions to modification & distribution.