I just went through this tutorial:
update-widget-in-onreceive-method
(btw: would you propose any improvements to that code?)
At the end someone mentions:
I’m just wondering if there is a way to extend this further so that when the device is asleep (screen off), the updates stop. Then when the device wakes up, the updates resume.
So my question: is there a way of doing this? how?
or is the alarmmanager automatically stopped? – I don’t think so.
You can specify whether the device will wake up when scheduling the AlarmManager.
Quote from the documentation:
Same goes for
AlarmManager.RTCandAlarmManager.RTC_WAKEUPSo you probably want one of the two
AlarmManager.RTCorAlarmManager.ELAPSED_REALTIME. These continue while the device is awake and stop when the device is in standby. If this alarm is triggered while the device is asleep it will be delivered when the user turns the device back on though, exactly what you want. And no, the AlarmManagers scheduled alarms are not cancelled automatically in general.The part mentioned here can be found in this part of the tutorial, specific this line: