I'm using
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 0, DURATION, broadcast);
To schedule an repeating task that should only be executed if the device is not asleep. As I understand the API on the AlarmManager the intent will be called once the device wakes up from sleep.
Now when is an Android device asleep? For testing I set the duration to two minutes and connected the device to my machine. Now I'm watching logcat and every two minutes it will spit out my debug message.
I always thought that an deactivated screen means that the devices starts sleeping. Or is my looking at the debug output preventing the device from sleeping? I also disconnected the USB connection and looked at the log after half an hour and I could see a call to my timer code even if the display was dark for more then 15 minutes.
How can I verify from which time the command is not executed anymore and what asleep refers to in the AlarmManager documentation? Is there a way to see from the logcat output when the device started sleeping?
In order to reduce power consumption and maintain privacy, all of our devices go dark after a period of non-use. A device may take 5 or 10 minutes or only 30 seconds, but the process is the same. The device's screen will turn black and it will look like it is turned off. This is actually the sleep mode.
Android's “Bedtime” mode, previously known as “Wind Down,” uses Do Not Disturb to silence calls, texts and notifications, while grayscale fades the colors on your phone to black and white, to reduce the draw to your screen.
A screen that is off, does not necessarily indicate a sleeping device. Applications can request wake locks that will keep the device awake while the screen is off. If another app has a timer that does not use inexact repeating, then the device will wake up for that as well.
Depending on the version of Android on your device, you can find a chart of your awake time in Settings - > About Phone -> Battery Use -> Then clicking on the graph up top. More information on wake locks can be found at http://developer.android.com/reference/android/os/PowerManager.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With