1
I have an alarm that is triggered every 5 minutes, and it calls an intentService to test a condition that if true, sends notification to the user, otherwise he does nothing.
But the intentService is only being called once, and only if I open the application (even if open I need to reopen), I even put to send a notification in case the condition is false to make sure that it is the alarmManager that is not repeating.
public class AlarmMgr {
AlarmManager alarmMgr;
public void Alarm(Context context) {
// Set the alarm here.
PendingIntent alarmIntent;
alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intentA = new Intent(context, BlockFoundService.class);
alarmIntent = PendingIntent.getBroadcast(context, 0, intentA, PendingIntent.FLAG_UPDATE_CURRENT);
// setRepeating() lets you specify a precise custom interval--in this case,
alarmMgr.setRepeating(AlarmManager.RTC, System.currentTimeMillis(),
1000 * 60 * 5 , alarmIntent);
}
public void CancelAlarm (Context context){
if (alarmMgr!= null) {
Intent intentA = new Intent(context, BlockFoundService.class);
PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intentA, PendingIntent.FLAG_UPDATE_CURRENT);
alarmMgr.cancel(alarmIntent);
}
}
}
I’ve had this problem, what API are you using? what level?
– PauloHDSousa