1

Can Android go to deep sleep while it is processing a broadcast in BroadcastRceiver? Is it required to create a partial wakelock as early as possible in BroadcastReceiver onReceive method or it can be created anywhere in onReceive method (and passed to a service)?

AlarmManager documentation states The Alarm Manager holds a CPU wake lock as long as the alarm receiver's onReceive() method is executing. This guarantees that the phone will not sleep until you have finished handling the broadcast. But what about other broadcasts? Or is this dependent only on sender of the broadcast?

DavisNT
  • 686
  • 7
  • 9
  • If the device is already asleep it may not even wake up to receive the broadcast : see http://stackoverflow.com/questions/16254420/broadcastreceiver-behavior-when-phone-is-asleep – Mr_and_Mrs_D May 04 '13 at 22:31

1 Answers1

1

Can Android go to deep sleep while it is processing a broadcast in BroadcastRceiver?

Generally, yes. One notable exception is if the BroadcastReceiver was triggered by AlarmManager and a getBroadcast() PendingIntent.

Is it required to create a partial wakelock as early as possible in BroadcastReceiver onReceive method or it can be created anywhere in onReceive method (and passed to a service)?

Well, you cannot pass a WakeLock to a service very easily, which is why I wrote WakefulIntentService.

But what about other broadcasts? Or is this dependent only on sender of the broadcast?

I am not aware of any other broadcast Intent that automatically holds a WakeLock, besides the aforementioned AlarmManager scenario. One that might would be SMS_RECEIVED, as an incoming SMS can also wake up the device.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • In my case these are AIRPLANE_MODE broadcasts sent from various applications trying to control it. Btw I tried to insert a Thread.sleep() in beginning of broadcast receiver and results surprised me - looks like phone didn't do to deep sleep during delay... – DavisNT May 04 '13 at 22:15
  • But anyway - I will acquire wake lock in beginning of broadcast receiver if I won't find any references to official Android documentation stating that broadcast receivers processing broadcasts prevent phone from sleeping. – DavisNT May 04 '13 at 22:28