Hello all, this is not so much of an issue that I need help with but more, an observation I had and I wanted to point it out for others as well as start a discussion. Of course, if there is something I can do better OR there is a possibility for Zebra to enhance the EMDK to correct this, then that would be appreciated too.
At first, I was having issues where the scanner would not return any results. The lights would light up but no beep, no barcode results. While troubleshooting with breakpoints, I noticed that one of the first things you should do is get the EMDK manager, which I was doing right away.
When the EMDK manager returns, it raises a callback, called:
void EMDKManager.IEMDKListener.OnOpened(EMDKManager emdkManager)
which in turn, will call InitScanner(); and at that point, you will be good to go, ready to scan, fully initialized.
However, when I was having issues, I noticed that the callback, OnOpened, would not raise at all or sometimes would eventually raise but take 30+ seconds or even minutes which of course delays the InitScanner by that amount of time and you cannot scan during this time.
The culprit that I found is OnPause and OnDestroy must get raised to DeinitScanner and release the EMDK manager, which makes sense. But, guess what, when you are debugging in Visual Studio and you hit stop, it instantly stops and from what I can tell, OnPause and OnDestroy do not get called. This leaves the EMDK manager out there.
How can you tell? Go to Android Settings > Apps > Running and you will see "EMDK Service" is running even when your app is closed or you are not debugging. If the EMDK Service is running, it causes this slowdown of the callback the next time you try to run your app. So, you have to do one of two things:
1. When debugging, make sure to hit back arrow on the android device BEFORE you stop the debugger.
2. You can go to apps > Running and select the EMDK Service and then click "Force Stop". This will kill it and you will be good.
If you shutdown the app gracefully (number 1 above) you will see that the EMDK service is removed from the running apps.
This happens even on the BarcodeScanningTutorial provided by Zebra for the EMDK. You can see this happen by loading the tutorial into Visual Studio and start debugging. The first time, all will be fine. Now, click the stop button to stop debugging and try to start back up. While you were stopped, you could note that the EMDK service never closes. You could also note the delay on the callback OnOpened. When the demo is started back up, you will note it is stuck on "Status: EMDK Opened successfully ..." and doesn't go to this status "Scanner is idle and ready to submit read." like it should. Finally, you will note that you cannot scan a barcode during all of this.
While this seems to be an issue with debugging in Visual Studio, it has me concerned. What happens if my app gets in a weird state in production and the service does not get stopped properly?
That said, I believe that Zebra should look at this. It seems that even if the EMDK service IS still running when the app is started and the EMDK manager tries to GetEMDKManager on startup, it should be able to either return the currently running instance or kill and restart or something in a more timely manner rather than sitting there doing nothing.
Hope this helps some people and hopefully there is a workaround or something to ensure this won't be an issue.