Home » Android » android – How to implement yearly and monthly repeating alarms?

android – How to implement yearly and monthly repeating alarms?

Posted by: admin June 15, 2020 Leave a comment


I want to set monthly and yearly alarm in my app.I did this for weekly. AlarmManager.INTERVAL_DAY helped me for that.But i could not find good way to implement monthly and yearly repeat.

Searched so far:



Is any other way available to do this? Any help appreciated.

How to&Answers:

I think that, you have two inherent issues with this approach:

  • AlarmManager will not accept large time intervals because the number of millis will overflow the argument

  • I do not think Alarms will survive reboots of your phone that will most certainly happen during such a long period of time.

I advice that you store each alarm in a safe place and use a combination of AlarmManager and onBoot receivers to check if one of the alarms from your list must be fired this very day and just reschedule an alarm to wake you up tomorrow if none does.

public class AlarmService extends Service {
  //compat to support older devices
  public void onStart(Intent intent, int startId) {
      onStartCommand(intent, 0, startId);

  public int onStartCommand (Intent intent, int flags, int startId){
   //your method to check if an alarm must be fired today

   //reschedule me to check again tomorrow
    Intent serviceIntent = new Intent(AlarmService.this,AlarmService.class);
    PendingIntent restartServiceIntent = PendingIntent.getService(AlarmService.this, 0, serviceIntent,0);
    AlarmManager alarms = (AlarmManager)getSystemService(ALARM_SERVICE);
    // cancel previous alarm
    // schedule alarm for today + 1 day
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, 1);

    // schedule the alarm
    alarms.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), restartServiceIntent);


To start your service at boot time use this :

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class serviceAutoLauncher  extends BroadcastReceiver{

  public void onReceive(Context context, Intent intent) {
      Intent serviceIntent = new Intent(context,AlarmService.class);


Finally add this to your manifest to schedule your serviceAutoLauncher to be launched at each boot:

    <receiver android:name="serviceAutoLauncher">
            <action android:name="android.intent.action.BOOT_COMPLETED"></action>
            <category android:name="android.intent.category.HOME"></category>


I solved the issue. In my app,multipal alarms were set with different repeating time intervals.So in my broadcast receiver for alarm,i re-scheduled the alarm based on for what time it was scheduled to be repeated.I used calendar object to add month and year accordinly and again set it for next alarm.i used code like this(for scheduling it for next month)-

PendingIntent sender = PendingIntent.getBroadcast(context,Integer.parseInt(Long.toString(id)), intent1, 0);                             

Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, 30);

AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

calendar.add(Calendar.MONTH, 1);

am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);


To add to Laurent’s response. To abstract from calculating recurrence manually I suggest to take a look at this RFC-2445 implementation. It works fine on Android and can save you a lot of pain.