androidalarmmanageralarmandroid-alarmsrepeatingalarm

Set repeat alarm for every year in android


I am building an alarm application in android.Till now i am able to create repeat alarm for every day,week and every month.

Now my requirement is to set repeat alarm for every year. TIA


Solution

  • You can set alarm after every year, each time alarm is fired you can start a new service intent which will be set alarm for next consecutive year.

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    int year = calendar.get(Calendar.YEAR);
    calendar.set(Calendar.YEAR, year + 1);
    
    alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 0, alarmIntent);