title: Android repeating alarm (AlarmManager.INTERVAL_DAY)
body: <p>I am trying to implement a daily alarm.</p>
  
  <pre><code>    Intent intent = new Intent(mActivity, AlarmReceiver.class);
      intent.putExtra("weekdays", weekdays);
      PendingIntent pendingIntent = PendingIntent.getBroadcast(mActivity.getApplicationContext(), weekdays ? WEEKDAYS_ID : WEEKENDS_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      Calendar current = Calendar.getInstance();
      time.set(Calendar.SECOND, 0); // time a type of Calendar object which is set from TimePicker
      long timeDifference = time.getTimeInMillis() - current.getTimeInMillis();
      long triggerAt = (timeDifference &gt; 0 ? time.getTimeInMillis() : AlarmManager.INTERVAL_DAY + timeDifference);
      mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, triggerAt, AlarmManager.INTERVAL_DAY, pendingIntent);
  </code></pre>
  
  <p>It works fine if I set a time in future.
  But if the time difference is negative (current time- 8:00, picked time- 7:45), the repeating alarm is set instantly and the broadcast receiver is fired!
  Though I have added <code>AlarmManager.INTERVAL_DAY</code> with the <code>timeDifference</code> to set it after a day, it isn't working.</p>
  
  <p>Also, The <code>AlarmManager.INTERVAL_DAY</code> value is (86400000) which is smaller than the current time in milis (1387869223432), so adding it doesn't make much difference!</p>
  
  <p>What am I missing here?</p>
  
  <p>Ok, this is not working.</p>
  
  <pre><code>long triggerAt = (timeDifference &gt; 0 ? time.getTimeInMillis() : time.getTimeInMillis() + AlarmManager.INTERVAL_DAY + timeDifference);
  </code></pre>
  
  <p>After debugging, I found that if I set earlier time, then add one day time - difference then the trigger time gets lower than the current time!</p>
  
  <pre><code>Alarm time: 1388073636969 (8am) current time: 1388130756977 (11:50pm)
  Difference: -57120008
  Alarm to be Triggered: 1388102916961
   // its alarm time (8am) + one day interval (1 day) -difference (4hr)
  </code></pre>
  
  <p>How come trigger time gets smaller than current time??</p>