Pol Hallen
Pol Hallen

Reputation: 1862

alarmmanager set at every years

This code set an alarm at 25/12/2012. How is possible replace 2012 with every years?

Calendar cal = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault());
cal.set(Calendar.DATE,25);
cal.set(Calendar.MONTH,Calendar.DECEMBER);  
cal.set(Calendar.YEAR,2012);

Upvotes: 0

Views: 181

Answers (1)

Nikolay Elenkov
Nikolay Elenkov

Reputation: 52936

Keep in mind that alarms are not persisted to disk. Since it is very likely that your device will be reset, rebooted or simply run out of battery long before the alarm is triggered, using the AlarmManager for such long periods is not a good idea. You could have a broadcast receiver for device boot (BOOT_COMPLETED) and register your alarm, but that too is not too reliable and may not be available on ICS and later (not unless the user started your app manually).

The comment above is correct though, one way to do this is for each alarm to schedule the next one.

Upvotes: 1

Related Questions