Search code examples
androidalarmmanagerandroid-alarms

Scheduling repeating alarms


I'm scheduling repeating alarms in order to execute service one a period of time.

// Set the alarm to start at approximately 24:05 a.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 24);
calendar.set(Calendar.MINUTE, 5);

alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
        AlarmManager.INTERVAL_DAY, ); 

Some question about the implementation :

  1. What happens if user delete the application (including the service), will something crash on the next alarm ?
  2. Again if user delete the application, the alarms will continue running ? If so, how can I cancel any repeating alarms ?
  3. Where/When is the best place/time to initiate the repeating alarms ? Should I wrap it with "only once" block ?

Solution

  • I'm not completely sure but I can give answers for your questions;

    1- If user deletes your application and service, I think anything crash on the next alarm because I think your application is running on the service. (if there is no service, alarm does not works i think)

    2- If user deletes your app, alarm will works but if service doesn't works, alarm does not works.

    3- I think there is some options for repeating alarms and user can select one of this options.