What happens when the device is in sleep mode?
That depends upon your type of alarm and the component your PendingIntent
is to invoke.
If your alarm type ends in _WAKEUP
, and you are using a broadcast PendingIntent
, the device will wake up and remain awake through the call to onReceive()
of the BroadcastReceiver
. Once onReceive()
returns, the device can fall asleep again. This is why WakefulIntentService
and WakefulBroadcastRecevier
were created -- to offer tested patterns for how to pass control to an IntentService
and keep the device awake while the service completes its work.
If your alarm type ends in _WAKEUP
and you are not using a broadcast PendingIntent
, as the saying goes, your mileage may vary. You may not get control before the device falls back asleep. This is not a recommended pattern.
If your alarm types does not end in _WAKEUP
, the device will not wake up due to your alarm.
With respect to the Notification
, given the nature of the API, one hopes that it is the OS' responsibility to keep the device awake long enough for the ringtone or vibration pattern to play, as we do not know the precise instant when the Notification
appears, nor do we know whether the ringtone will play (e.g., device is on silent mode).