jtnire
jtnire

Reputation: 1358

Android - Do I need a WakeLock?

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

Upvotes: 1

Views: 435

Answers (2)

CommonsWare
CommonsWare

Reputation: 1006549

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.

Upvotes: 2

Yury
Yury

Reputation: 20936

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.

Upvotes: 1

Related Questions