Pergunta

I just cannot my Alarms to get fired. All problems regarding canceling, saving and restoring after reboot have already been taken care of. It's just that nothing happens at the expected time. I tried to start an Activity instead of the Service, but there's no difference. Actually, I wonder a bit because it's nowhere stated that the Service object should not only be created, but started. Is that automatic because of the type? Directly calling startService() from an Activity works fine, so the problem lies in the Alarm, not in the Service. It's a real pity that the alarms set by the current applications cannot be listed to check whether everything is fine.

Any help is appreciated.

long INTERVAL_WEEK = AlarmManager.INTERVAL_DAY * 7;
DateFormat df = new SimpleDateFormat("E, yyyy-MM-dd'T'HH:mmZ");
Log.d(TAG, "next alarm " + df.format(cal.getTime())); // checking the right time
Intent showNotificationIntent = new Intent(context, MyNotificationService.class);
alarmIntent = PendingIntent.getBroadcast(context, dayOfWeek, showNotificationIntent, 0);
getAlarmManager(context).setInexactRepeating(AlarmManager.RTC, cal.getTimeInMillis(),
    INTERVAL_WEEK, alarmIntent);
Foi útil?

Solução

You should be using PendingIntent.getService() instead of PendingIntent.getBroadcast() when creating your PendingIntent.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top