1

I have a BroadcastReceiver that listen for the "SMS_SENT" Intent after an SMS has been sent. As far as I know, SMSManager does provide a wakelock so that it can actually send the SMS (I don't have any proof of this, but common sense would tell me that this is the case).

However, my BroadcastReceiver calls a WakefulIntentService, which uses its own wakelock, so that is ok. However, what about the receiver itself? Do I need to create a new wakelock so that I can guarantee that the WakefulIntentService is called? Or can I just safely ignore this, just like one can do with a receiver for AlarmManager?

Thanks

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
jtnire
  • 1,348
  • 5
  • 21
  • 32

2 Answers2

2

However, what about the receiver itself? Do I need to create a new wakelock so that I can guarantee that the WakefulIntentService is called?

Once your receiver calls WakefulIntentService.sendWakefulWork(), the WakefulIntentService engine acquires a WakeLock.

So long as you are not doing much work before that call, you should be fine.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks. The broadcast receiver just has a switch statement that populates the extras in the intent accordingly for the call to the wakeful intent service. Does this sound acceptable? – jtnire Mar 20 '12 at 23:46
  • @jtnire: That by itself should add little overhead. I do not know if the SMS broadcast process has its own `WakeLock`. It is conceivable that the device could fall asleep during SMS delivery before it gets to you, though that seems unlikely, and there's nothing you can do about it anyway. – CommonsWare Mar 20 '12 at 23:56
1

I think you do not need to create a wakelock for waiting the response. Here are my thoughts. First of all, imagine that your broadcast receiver for some reason does not receive the broadcast. Then you will have an active wakelock. Secondly, it seems to me that the broadcast should activate your phone (because I've never seen sms application examples where a wakelock is created). So to my point of view you do not need to create a wakelock.

Yury
  • 20,618
  • 7
  • 58
  • 86