4 Replies Latest reply on May 26, 2017 4:47 AM by Darryn Campbell

    EMDK cannot restart after emdk.release()

    Tianyu Meng

      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:

      @Override
      protected void onStop() {

         super.onStop();

        Log.i("ScannerActivity", "OnStop");

        deInitScanner();

         if (emdkManager != null) {

         emdkManager.release();

        }

      }

       

      @Override
      protected 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.

        • Re: EMDK cannot restart after emdk.release()
          Darryn Campbell

          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.

            • Re: EMDK cannot restart after emdk.release()
              Tianyu Meng

              Hi Darryn,

              Thanks for reply. I did try to wrapper the emdk listener in the separate class, it has the same issue. This issue only happened in the following situation: You have 2 activities and both of them are using EMDK barcode scanner and both of them stay in the activity lifecycle. If I destroy one of them then start the other one, it works fine. But if I start the second activity with the first activity stay in lifecycle (without destroy it), only the second activity works and after I destroy second activity, the first activity still does not work.

               

              I see the code sample you provided, I do the exactly same. The only difference is, I move what you write in onDestroy() to onStop() and move what you write in onCreate() to onStart(), to make sure when the activity goes to the background and then back to the foreground, emdk can be initialized again. But it does not work for me. Do you have any idea that how to restart emdk service without destroy and onCreate the activity again? Is there any way I can release the emdk manager and then get it again in an activity lifecycle?

              • Re: EMDK cannot restart after emdk.release()
                Tianyu Meng

                And by the way, I am using EMDK 3.1 with Android 4.4.3. Your sample code seems like a version 6.0. Do you think this issue can be fixed if I upgrade the EMDK library to 6.0? I want the app running on TC-70 and TC-75. Do  I need to do any upgrade to my devices? I have checked the instruction, it seems I need to run a apk on the device if I upgrade the emdk lib?