Barcode scanner stops working after some time of inactivity

Hello, I noticed that if i dont use scanner for a while (until Android goes to sleep and locks it's screen) the scanner stops working. After i wake up the device my application cannot scan any more. I use Android EMDK. How can i restart the scanner after app returns from sleeping?

Tomislav Kralj
For what is worth it does not

For what is worth it does not happen if device is connected in USB debugging mode. If app works stand alone (not attached to a debugger) then this happens.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi, yes on newer devices the

Hi, yes on newer devices the scanner will sleep when the device sleeps as a power saving feature.  The recommended approach is to disable the scanner during onPause() and reenable it during onResume (see the sample at samples-emdkforandroid-6_6/MainActivity.java at BarcodeSample1 · Zebra/samples-emdkforandroid-6_6 · GitHub )

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Tomislav Kralj
Thanks. But now when i open

Thanks. But now when i open another activity barcode reader stops working.

I created a class:

public class ZebraEMDK extends AppCompatActivity implements EMDKListener, DataListener, StatusListener, ScannerConnectionListener{

and i have activityA and ActivityB that extends this clas. When i start ActivityA scanner works as expected but when i start another activity it stops. Why is that ?

Tomislav Kralj

Voditelj razvoja

+385 091 724-0724 (mob)

tomislav@softlab.hr

Softlab obrt

S. Radića 16, 10430 Samobor

Croatia

www.softlab.hr

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Peter Arcuri
In the event you wish to

In the event you wish to pursue the EMDK path, there is a way to achieve your original design and address the non-responsiveness issue. First things, I would suggest creating an Interface Class that sits between your UI-thread and your ZebraEMDK class. The interface class would simply have 3 calls; onDataScanned passing scanData, onStatusUpdate passing scanStatus and onError. For this discussion we'll call the interface class I_onScannerEvent.

Your UI Activities would implement the I_onScannerEvent class in order to call its methods. For instance onDataScanned (String scanData) method is used to populate the respective field in the UI. Similar method is created for the scanner status, if that is required.

Each UI Activities would then call the ZebraEMDK class' methods to getinstance of ZebraEMDK while passing on the UI activity object. This is done in onResume. Entry point to your ZebraEMDK class would look something like this; ZebraEMDK getInstance(Context context). Context is the UI activity object. You will need the UI activity object when calling the I_onScannerEvent methods from ZebraEMDK class. For example, UIactivity.onDataScanned(scanData) or (scanStatus); Use background thread when calling the I_onScannerEvent class.

Naturally between the entry point and the last call you would instantiate EMDKManager, barcodeManager and Scanner objects in your ZebraEMDK class.

BTW, releasing EMDK  resources in the onPause or onStop method of UI activity would address the non-scan issue as to navigate from one UI activity to another and in the event of a suspend condition within an UI activity.

Hope this helps.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Tomislav Kralj
Hello, can i turn off this

Hello, can i turn off this sleeping feature using config ?

Tomislav Kralj

Voditelj razvoja

+385 091 724-0724 (mob)

tomislav@softlab.hr

Softlab obrt

S. Radića 16, 10430 Samobor

Croatia

www.softlab.hr

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
It may be easier to use

It may be easier to use DataWedge rather than the EMDK, have you looked into that at all?  You could configure DataWedge to scan barcodes when either of your activities are in the foreground (specify the associated activity in the profile you create), that way you would not have to worry about the scanner going to sleep or disabling / re-enabling the scanner between activities.  You would receive the scanned barcodes programmatically via Intent.  More information is here: Intent Output - Zebra Technologies TechDocs

It is not possible to prevent the scanner sleep behaviour I do not believe.  In code, you would need to disable the scanner whenever an activity pauses and reenable it whneever the second activity resumes, assuming you do not go down the Datawedge route.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Tomislav Kralj
Thank you i will try

Thank you i will try DataWedge option.

Tomislav Kralj

Voditelj razvoja

+385 091 724-0724 (mob)

tomislav@softlab.hr

Softlab obrt

S. Radića 16, 10430 Samobor

Croatia

www.softlab.hr

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Ross Rogers
.

[deleted]

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments