title: Repeating Alarm for specific days of week android
body: <p>In my application I have a functionality to trigger alarm in 4 senerios:</p>
  
  <ul>
  <li>Only once for a user chosen date and time</li>
  <li>Daily for chosen time</li>
  <li>Weekly according to chosen date and time</li>
  <li>User chosen custom days of the week</li>
  </ul>
  
  <p>I successfully implement the first 3 senerios by using the follow:</p>
  
  <p><strong>Only once:</strong></p>
  
  <pre><code>Calendar calendar = Calendar.getInstance();
  
          calendar.set(Calendar.YEAR, Integer.parseInt(date[0]));
          calendar.set(Calendar.MONTH, (Integer.parseInt(date[1])) - 1);
          calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(date[2]));
          calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time[0]));
          calendar.set(Calendar.MINUTE, Integer.parseInt(time[1]));
          calendar.set(Calendar.SECOND, 0);
  
          alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
  </code></pre>
  
  <p><strong>For daily scheduling:</strong> </p>
  
  <pre><code>Calendar calendar = Calendar.getInstance();
              calendar.setTimeInMillis(System.currentTimeMillis());
              calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time[0]));
              calendar.set(Calendar.MINUTE, Integer.parseInt(time[1]));
              calendar.set(Calendar.SECOND, 0);
  
              alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
  </code></pre>
  
  <p><strong>For weekly scheduling (as per system date):</strong></p>
  
  <pre><code>Calendar calendar = Calendar.getInstance();
          calendar.setTimeInMillis(System.currentTimeMillis());
  
          calendar.set(Calendar.DAY_OF_WEEK, dayOfWeek);
          calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time[0]));
          calendar.set(Calendar.MINUTE, Integer.parseInt(time[1]));
          calendar.set(Calendar.SECOND, 0);
          //long interval = calendar.getTimeInMillis() + 604800000L;
          alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY * 7, pendingIntent);
  </code></pre>
  
  <p>For custom weekdays chosen by user (ex. only for monday and friday, repeated weekly) I am using the same code that I used for weekly scheduling by iteration. But its not working for monday (which is set before friday) and working for friday. Also, it does not trigger the alarm for today if today (system date) is a monday or a friday. </p>
  
  <p><strong>So how do i implement weekly alarm scheduling for custom days of the week?</strong></p>