Scanner Does Not Turn Off EMDK 5

J Jon-Luke West 3 years 6 months ago
23 1 0

Developing an application for Android MC92KK with EMDK 5.
 
After initializing the scanner in a Fragment and then completely destroying the parent Activity, but not closing the application because I am now in a different Activity without scanning, the scanner never turns off.  It seems to be stuck in a continuous scan mode somehow.
 
if (emdkManager != null) {    // Clean up the objects created by EMDK manager    if (scanner != null) {    try {    //scanner.cancelRead();    scanner.removeDataListener(this);    scanner.removeStatusListener(this);    scanner.disable();     } catch (ScannerException e) {   e.printStackTrace();    }   }    emdkManager.release();    emdkManager = null; } 
 
I have gone as far as the code above in the onDestroy() for the fragment, but nothing will get the scanner to not turn on when I press the trigger except for completely closing the application.  The callbacks do not fire when I am on a different Fragment or Activity; so it doesn't seem to negatively impact the function of the application at this time.  I know this is going to be reported as a bug as soon as I hand it over to the User Acceptance Testing team though.  Am I missing something painfully obvious?
 
EDIT Here are a couple of examples of application states:
 
Example 1
 
Application Starts -> Activity 1 Starts -> Activity 2 Starts -> Activity 3 Starts -> Activity 3 Loads Fragment 1 -> Fragment 1 Initializes Scanning ->  Activity 3 Loads Fragment 2 on top of Fragment 1 (Fragment 1's view is destroyed and I disable scanning with the above code) -> Scanner will turn on when the trigger is pressed from Fragment 2
 
Example 2
Application Starts -> Activity 1 Starts -> Activity 2 Starts -> Activity 3 Starts -> Activity 3 Loads Fragment 1 -> Fragment 1 Initializes Scanning -> Destroy Activity 3 and Fragment 1 (thus disabling scanning) -> Scanner will turn on when the trigger is pressed from Activity 2 -> Destroy Activity 2 -> Scanner will turn on when the trigger is pressed from Activity 1 -> Close application -> Scanner is disabled
 
 
Thank you in advance for your help.
 
Added some more clarification for where I am in the application

Please Register or Login to post a reply

1 Replies

Y Yanis Dalabiras

Hi,

The first thing to check is that you don't have a default DataWedge profile active when Activity 2 is shown.  Out of the box DataWedge will have Profile0 defined (and possibly enabled) so the safest thing to do would be to disable DataWedge if you're unsure ( DataWedge Setup - Zebra Technologies Techdocs ).

Also, de-initialising the scanner in onDestroy() is too late.  OnDestroy() is not guaranteed to be called, please see Activity | Android Developers​  .It is recommended to shut down the scanner in the application's (or fragment's in this case) onPause() and re-initialise in the onResume(), https://github.com/Zebra/samples-emdkforandroid-5_0/blob/BarcodeSample1…​ Anecdotally the performance is not noticeably impacted when switching applications

Darryn

CONTACT
Can’t find what you’re looking for?