4 Replies Latest reply on Aug 18, 2016 4:59 AM by Petr Brant

    Barcode API - very slow

    Petr Brant

      Good morning,

       

      we have Android Xamarin application with Barcode Scanner API. On every Activity we have InitScanner method OnResume event and DeinitScanner method on OnPause event.

       

      public void InitScanner(bool enableScannerOnStartup)
      {
          if (emdkManager != null)
          {
              if (barcodeManager == null)
              {
                  try
                  {
                      barcodeManager = (BarcodeManager) emdkManager.GetInstance(EMDKManager.FEATURE_TYPE.Barcode);
                      scanner = barcodeManager.GetDevice(BarcodeManager.DeviceIdentifier.Default);
                      if (scanner != null)
                      {
                          scanner.Data += scanner_Data;
                          scanner.Enable();
                      }
                  }
                  catch (ScannerException e)
                  {
                      //LOG
                  }
                  catch (Exception e)
                  {
                      //LOG
                  }
              }
          }
      }
      
      public void DeinitScanner()
      {
          if (emdkManager != null)
          {
              if (scanner != null)
              {
                  try
                  {
                      scanner.Data -= scanner_Data;
                      scanner.Status -= scanner_Status;
                      scanner.Disable();
                  }
                  catch (ScannerException e)
                  {
                      //LOG
                  }
              }
              if (barcodeManager != null)
              {
                  emdkManager.Release(EMDKManager.FEATURE_TYPE.Barcode);
              }
              barcodeManager = null;
              scanner = null;
          }
      }
      

       

       

      InitScanner and DeinitScanner is called for every Activity. We have problem with speed (Init takes aproximately 4 seconds - on every StartActivity). What is the best solution how to speed up application (BarcodeAPI, DataWedge profile, create scanner singleton)?

       

      Thank you for advice.

        • Re: Barcode API - very slow
          Bill Hecox

          Hello Petr,

               Sorry for the delay in answering your question. Could you provide a full sample app that displays this issue? A full sample will help greatly in tracking down the issue.

            • Re: Barcode API - very slow
              Petr Brant

              Hello Bill,

               

              Test application to download, compile and run - https://kodys-my.sharepoint.com/personal/petr_brant_kodys_cz/_layouts/15/guestaccess.aspx?guestaccesstoken=DHluxqZy%2fD4fuwfVaBKw77RqKehBDpthOWIg84VTW2M%3d&docid=0fcbfc7b150704851b1ebf871ae84cb7c&rev=1

               

              After run, there is timer between click on button and scanner initialization complete (application create new instance of MainActivity). Average value is 1.2 second !!! Too long to wait on every activity start - without scanner initialization there is 0.05 second.

               

              We can achieve better results with using Datawedge profile broadcast intents, but there is an issue when you go back from activity - we have opened ticket to tech support (#3512060 if you would like to help to resolve).

               

              With scanner initialization:

              Screenshot_2016-07-25-13-47-24[1].png

              Without scanner initialization:

              Screenshot_2016-07-25-13-45-52[1].png

                • Re: Barcode API - very slow
                  Pietro Maggi

                  Hi Petr,

                  you just hit the "examples too simple to be useful" roadblock.

                   

                  All the sample Zebra provides are a single activity with the EMDK objects lifecycle linked to the Activity Lifecycle, good to show some basics but a bit lacking if you want to build a bigger app with the same structure.

                   

                  First, Activating and Deactivating the Barcode API takes some time, simply because all the Scanner Framework and the HW needs to be activated and deactivated, if you need to transition between Activities expecting to be able to use the scanner heavily, this is not going to fly.

                  You need to detach the Barcode API Instance lifecycle from the activities lifecycle.

                  • Implement an EMDKWrapper (you can find something in this discussion https://developer.zebra.com/message/88185?et=watches.email.thread#88185 )
                  • link the EMDKWrapper to the application lifecycle, deactivating the scanner when the app goes in background and reactivating it when the app comes in foreground
                  • pass the scanner events (probably you need to pass just the data with some metadata) to the Activity in foreground using some message bus or the Xamarin MessagingCenter system.

                  Either way, you need to detach the two lifecycle... or use a single Activity :-)

                  Here's a similar discussion around these topics: https://developer.zebra.com/message/90639?et=watches.email.thread#90639

                   

                  I'll take a look at your issues with DataWedge on the support portal.

                   

                  Ciao

                  ~Pietro

                    • Re: Barcode API - very slow
                      Petr Brant

                      Hi Pietro,

                       

                      thanks for your response. IntPtr thread is very good as information how to handle with this error.

                       

                      Writing background scanner service (singletons are evil) is similar to write small "Datawedge" application :-), so we migrate whole application to use Datawedge.

                       

                      If you have time, please look at the issue - ticket was escaleted and now has a number SPR#30284.

                       

                      Best regards,

                      Petr