Trying to write a Broadcast Receiver that processes incoming SMSs. Do I need to use a wake lock / partial wake lock, for this application to work, in spite of device going to sleep due to lack of foreground activity ?
Asked
Active
Viewed 312 times
1 Answers
1
I tend to extend a WakefulBroadcastReceiver to simplify things, so in a way yes. For example:
public class MyBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final ComponentName comp = new ComponentName(context.getPackageName(),
MyIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}

alpinescrambler
- 1,934
- 16
- 26
-
Thanks for answering. While I do understand the BroadcastReceiver based implementation, the 'WakefulBroadcastReceiver' is very new to me. At the outset, it looks like a great simplification (compared to code I'd have to write to acquire and release the partial wake-lock), but I was wondering if there was a way to avoid using a Service ! – bdutta74 Sep 08 '14 at 18:14