I am developing a small application that scans 2D barcodes and then sends each barcode to an IntentService, where a longer task is performed.
When an action is displayed, it should prevent the device from sleeping until the barcode is processed in the service. If the service completes processing, it stops itself, but activity should still be visible.
I want SCREEN_DIM_WAKE_LOCK WakeLock to be enabled during the activity lifecycle, but since this type does not prevent the processor from sleeping, I also need to get PARTIAL_WAKE_LOCK in activity when scanning a new 2D code, and release it in the intent service after processing it.
The purpose of SCREEN_DIM_WAKE_LOCK is to avoid the inconvenience of the user pressing the power button every few seconds to wake the device and read a new barcode. The user will have to read a large number of codes one after another, and activity should be even for short intervals when there is no interaction with the user.
I know that in Android there is no 100% guarantee that the application is on top and not closed, or in the foreground due to several conditions that my application cannot control, but I would like as far as possible.
So you can hold multiple WakeLocks? Where can they be declared as accessible by both activity and service? (Singleton, application extension?)
source share