Either use Commonsware's WakefulIntentService or do this :
class YourService extends IntentService {
private static final String LOCK_NAME = YourService.class.getName()
+ ".Lock";
private static volatile WakeLock lockStatic = null; // notice static
synchronized private static PowerManager.WakeLock getLock(Context context) {
if (lockStatic == null) {
PowerManager mgr = (PowerManager) context
.getSystemService(Context.POWER_SERVICE);
lockStatic = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
LOCK_NAME);
lockStatic.setReferenceCounted(true);
}
return (lockStatic);
}
public static void startYourService(Context ctxt, Intent i) { // STATIC
getLock(ctxt.getApplicationContext()).acquire();
ctxt.startService(i);
}
public YourService(String name) {
super(name);
setIntentRedelivery(true);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
PowerManager.WakeLock lock = getLock(this.getApplicationContext());
if (!lock.isHeld() || (flags & START_FLAG_REDELIVERY) != 0) {
lock.acquire();
}
super.onStartCommand(intent, flags, startId);
return (START_REDELIVER_INTENT);
}
@Override
protected void onHandleIntent(Intent intent) {
try {
// do your thing
} finally {
PowerManager.WakeLock lock = getLock(this.getApplicationContext());
if (lock.isHeld()) lock.release();
}
}
}
and in your receiver :
Bundle bundle = intent.getExtras();
String message = bundle.getString("alarm_message");
// Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
Intent myIntent = new Intent(context, SendOutstandingTransactions.class);
myIntent.setAction("com.carefreegroup.startatboot.MyService");
YourService.startYourService(context, myIntent)
which is actually the core from @CommonsWare WakefulIntentService (not sure about the START_FLAG_REDELIVERY, I should ask one of these days)