Я нашел ответ на мою проблему:
private boolean service_started=false;
private PendingIntent mAlarmSender;
@Override
public void onReceive(Context context, Intent intent) {
if(!service_started){
// Create an IntentSender that will launch our service, to be scheduled
// with the alarm manager.
mAlarmSender = PendingIntent.getService(context,
0, new Intent(context, UpdateService.class), 0);
//We want the alarm to go off 30 secs from now.
long firstTime = SystemClock.elapsedRealtime();
// Schedule the alarm!
AlarmManager am = (AlarmManager)context.getSystemService(context.ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
firstTime,30*1000, mAlarmSender);
service_started=true;
}
}
В конце концов, моя проблема заключалась в том, что я не правильно понял контекст:
(AlarmManager)getSystemService(ALARM_SERVICE);
изменено на
(AlarmManager) context.getSystemService (context.ALARM_SERVICE);