EMDK cannot restart after emdk.release()

T Tianyu Meng 3 years 6 months ago
183 2 0

Hi guys,
I am a developer working with emdk 3.1 on TC-75 android 4.4.3. The issue I have is that I have two activity A and B. When click button on A, it pop out B. Both activity implement EMDK interfaces. In A's on Stop, I call emdkManager.release() so I can use emdk in B. Everything works fine on B. But when I close B and release B's emdkManager so that I return to A, the emdk service on A will never work again. In A's onStart, I call emdkResult but it seems it does not open the emdk service.
 
this is the some pieces of code:
Activity A:
@Overrideprotected void onStop() {
   super.onStop();
  Log.i("ScannerActivity", "OnStop");
  deInitScanner();
   if (emdkManager != null) {
   emdkManager.release();
  }
}
 
@Overrideprotected void onStart() {
   super.onStart();
  Log.i("ScannerActivity", "OnStart");
  EMDKResults results = EMDKManager.getEMDKManager(getApplicationContext(), this);
   if (results.statusCode != EMDKResults.STATUS_CODE.SUCCESS) {
   txtStatus.setText("Status: " + "EMDKManager object request failed!");
  }
 
   new AsyncStatusUpdate().execute(statusString);
  startScan();
   new AsyncUiUpdate().execute(false);
 
}
 
 
public void deInitScanner() {
 
   if (scanner != null) {
   try {
 
   scanner.cancelRead();
   scanner.removeDataListener(this);
   scanner.removeStatusListener(this);
   scanner.disable();
   scanner = null;
 
  } catch (ScannerException e) {
 
   txtStatus.setText("deInitScanner-Status: " + e.getMessage());
   // getActionBar().setSubtitle("Status: " + e.getMessage());   }
 
   // scanner = null;   }
}
 
This is all the logs I have when I close the activity B and back to A.
05-23 09:26:04.977 31690-31690/com.monsanto.scanmaster.invetory.envDev D/com.symbol.emdk.EMDKServiceConnection: The EMDK Service will be connected soon (asynchronus call)!
05-23 09:26:04.987 31690-31690/com.monsanto.scanmaster.invetory.envDev D/com.symbol.emdk.EMDKServiceConnection: The EMDK Service is now connected!
05-23 09:26:05.808 5107-8323/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerUtils: start - getNumberOfScanners
05-23 09:26:05.808 5107-8323/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerUtils: end - getNumberOfScanners
05-23 09:26:05.808 5107-8323/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerUtils: start - getScannerInfo
05-23 09:26:05.808 5107-8323/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerUtils: end - getScannerInfo
05-23 09:26:05.808 5107-8323/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerUtils: start - getScannerInfo
05-23 09:26:05.808 5107-8323/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerUtils: end - getScannerInfo
05-23 09:26:05.808 5107-8323/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerUtils: start - getScannerInfo
05-23 09:26:05.808 5107-8323/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerUtils: end - getScannerInfo
05-23 09:26:05.808 5107-8323/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: SvcScanEventCallback::barcodeManager
05-23 09:26:05.818 5107-5121/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: SvcScanner::open
05-23 09:26:05.818 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: Scanner.open start: scannerIndex: 1
05-23 09:26:05.898 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: Scanner.open end
05-23 09:26:05.908 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: start - registerScanEventCallback
05-23 09:26:05.908 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: end - registerScanEventCallback
05-23 09:26:05.908 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: start - enable
05-23 09:26:06.248 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: end - enable
05-23 09:26:06.248 5107-5122/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerConfig: start - getCurrentParameters
05-23 09:26:06.248 5107-5122/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerConfig: end - getCurrentParameters
05-23 09:26:06.248 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: onScanEvent...STATUS: SCAN_STATUS_ENABLED
05-23 09:26:06.258 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: mScanner==null
05-23 09:26:06.258 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: onScanEvent...STATUS: SCAN_STATUS_ENABLED
05-23 09:26:06.258 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug. =========SVC SS MANAGER======== PID: 5107
05-23 09:26:06.258 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.heap native: allocated 2,005.30KB of 2,460.00KB (294.70KB free)
05-23 09:26:06.258 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.heap native: allocated 1.96MB of 2.40MB (0.29MB free)
05-23 09:26:06.258 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.memory: allocated: 12.00MB of 96.00MB (1.00MB free)
05-23 09:26:06.258 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.memory: allocated: 12,760.00KB of 98,304.00KB (1,124.00KB free)
05-23 09:26:06.258 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: onScanEvent...Triggering: IDLE
05-23 09:26:06.268 5107-8323/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerUtils: start - getScannerInfo
05-23 09:26:06.268 5107-8323/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerUtils: end - getScannerInfo
05-23 09:26:06.268 5107-5121/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: start - getScanStatus
05-23 09:26:06.268 5107-5121/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerConfigHelper: start - setParameters
05-23 09:26:06.278 5107-5121/? D/com.symbol.emdk.emdkservice.barcode.SvcScannerConfigHelper: end - setParameters
05-23 09:26:06.368 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: start - startScanning
05-23 09:26:06.368 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: end - startScanning
05-23 09:26:06.368 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: onScanEvent...STATUS: SCAN_STATUS_WAITFORTRIGGER
05-23 09:26:06.368 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: mScanner==null
05-23 09:26:06.368 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: onScanEvent...STATUS: SCAN_STATUS_WAITFORTRIGGER
05-23 09:26:06.378 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug. =========SVC SS MANAGER======== PID: 5107
05-23 09:26:06.378 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.heap native: allocated 2,007.92KB of 2,460.00KB (292.08KB free)
05-23 09:26:06.378 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.heap native: allocated 1.96MB of 2.40MB (0.29MB free)
05-23 09:26:06.378 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.memory: allocated: 12.00MB of 96.00MB (1.00MB free)
05-23 09:26:06.378 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.memory: allocated: 12,760.00KB of 98,304.00KB (1,076.00KB free)
05-23 09:26:06.378 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: onScanEvent...Triggering: WAITING
05-23 09:26:06.979 31690-31690/com.monsanto.scanmaster.invetory.envDev W/System.err: com.symbol.emdk.barcode.ScannerException: Failure
05-23 09:26:06.979 31690-31690/com.monsanto.scanmaster.invetory.envDev W/System.err:     at com.symbol.emdk.barcode.Scanner.cancelRead(Scanner.java:567)
05-23 09:26:06.979 31690-31690/com.monsanto.scanmaster.invetory.envDev W/System.err:     at com.symbol.emdk.barcode.Scanner.removeDataListener(Scanner.java:603)
05-23 09:26:07.029 31690-31690/com.monsanto.scanmaster.invetory.envDev W/System.err:     at com.symbol.emdk.barcode.Scanner.unRegisterDataNotification(Scanner.java:739)
05-23 09:26:07.029 31690-31690/com.monsanto.scanmaster.invetory.envDev W/System.err:     at com.symbol.emdk.barcode.Scanner.removeDataListener(Scanner.java:607)
05-23 09:26:07.039 31690-31690/com.monsanto.scanmaster.invetory.envDev W/System.err:     at com.symbol.emdk.barcode.Scanner.unRegisterStatusNotification(Scanner.java:773)
05-23 09:26:07.039 31690-31690/com.monsanto.scanmaster.invetory.envDev W/System.err:     at com.symbol.emdk.barcode.Scanner.removeStatusListener(Scanner.java:676)
05-23 09:26:07.049 31690-31690/com.monsanto.scanmaster.invetory.envDev W/System.err: com.symbol.emdk.barcode.ScannerException: Failure
05-23 09:26:07.049 31690-31690/com.monsanto.scanmaster.invetory.envDev W/System.err:     at com.symbol.emdk.barcode.Scanner.disable(Scanner.java:405)
05-23 09:26:07.049 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: start - getScanStatus
05-23 09:26:07.049 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: end - getScanStatus
05-23 09:26:07.049 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: start - stopScanning
05-23 09:26:07.049 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: end - stopScanning
05-23 09:26:07.049 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: onScanEvent...STATUS: SCAN_STATUS_ENABLED
05-23 09:26:07.049 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: mScanner==null
05-23 09:26:07.049 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: onScanEvent...STATUS: SCAN_STATUS_ENABLED
05-23 09:26:07.059 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug. =========SVC SS MANAGER======== PID: 5107
05-23 09:26:07.059 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.heap native: allocated 2,010.80KB of 2,460.00KB (289.20KB free)
05-23 09:26:07.059 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.heap native: allocated 1.96MB of 2.40MB (0.28MB free)
05-23 09:26:07.059 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.memory: allocated: 12.00MB of 96.00MB (1.00MB free)
05-23 09:26:07.059 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.memory: allocated: 12,760.00KB of 98,304.00KB (1,066.00KB free)
05-23 09:26:07.059 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: onScanEvent...Triggering: IDLE
05-23 09:26:07.059 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: start - getScanStatus
05-23 09:26:07.059 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: start - disable
05-23 09:26:07.079 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: end - disable
05-23 09:26:07.079 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: onScanEvent...STATUS: SCAN_STATUS_IDLE
05-23 09:26:07.079 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: mScanner==null
05-23 09:26:07.079 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: onScanEvent...STATUS: SCAN_STATUS_IDLE
05-23 09:26:07.089 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug. =========SVC SS MANAGER======== PID: 5107
05-23 09:26:07.089 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.heap native: allocated 2,004.13KB of 2,460.00KB (295.87KB free)
05-23 09:26:07.089 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.heap native: allocated 1.96MB of 2.40MB (0.29MB free)
05-23 09:26:07.089 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.memory: allocated: 12.00MB of 96.00MB (1.00MB free)
05-23 09:26:07.089 5107-32295/? D/tag: com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback_HL > debug.memory: allocated: 12,760.00KB of 98,304.00KB (1,055.00KB free)
05-23 09:26:07.089 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanEventCallback: onScanEvent...Triggering: DISABLED
05-23 09:26:07.089 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: start - release
05-23 09:26:07.089 5107-32295/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: end - release
05-23 09:26:07.089 5107-5121/? D/com.symbol.emdk.emdkservice.barcode.SvcScanner: set scanner object to null: sfScannerObj
05-23 09:26:07.139 31690-31690/com.monsanto.scanmaster.invetory.envDev D/com.symbol.emdk.EMDKServiceConnection: The connection to the EMDK Service was closed.!
 
 
 
My question is, when I back to A, how to make emdk service work again? Everything in activity B works fine. When I close B and back A, scanner.read() will give me the error. It seems emdk service has been closed.

Please Register or Login to post a reply

2 Replies

S Simone Gabellieri

I had the same problem as you described.With the info provided by ​ my colleague have implemented the EMDK in a BaseActivity which every Activity can extend to read data.

In your Activity X, extends from BaseActivity and then you can simply implement onQRCodeReaded(String data) method to read the data.Here full GIST BaseActivity: Implement Zebra EMDK 7.0 on BaseActivity for multiple Activities · GitHub

Thank You Darren

Y Yanis Dalabiras

Hi,

It does sound like something is not being closed down correctly but it is difficult to say what the root cause could be.

Could you share scanning between the activities?  Perhaps wrap the scanning logic in a separate class you could pass between activities?  Rather than shut down the hardware when switching between activities, since closing the hardware takes time it would negatively impact the user experience.

For an example of a known working model of enable() and release() please refer to the sample at samples-emdkforandroid-6_0/MainActivity.java at BarcodeSample1 · Zebra/samples-emdkforandroid-6_0 · GitHub , it is not exactly what you are trying to achieve as there is only one activity but it is a good starting point.

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