title: Alarm everyday at 5AM morning
body: <p>I am working on an android application where I need to trigger an alarm every morning at 5 am. I have already used the concept of <code>Intent</code>(below is the code) and putting <code>AlarmManager</code> in the <code>Service</code>. But I didnt get the problem solution from both implementations. I am just looking for a perfect solution for this. If I add a reminder to the <code>calendar</code> for 1 month once the application is opened for the first time I guess that might work. But if there is any better solution for this, then please provide. It should trigger an alarm at 5 AM every day no matter what. How can I achieve this?</p>
  
  <pre><code>alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
          Intent alarmIntent = new Intent(this, MyStartServiceReceiver.class);
          PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 100, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
          Calendar calendar = Calendar.getInstance();
          calendar.set(Calendar.HOUR_OF_DAY, 5);
          calendar.set(Calendar.MINUTE, 5);
          calendar.set(Calendar.SECOND, 0);
          calendar.set(Calendar.AM_PM, Calendar.AM);
          if (System.currentTimeMillis() &gt; calendar.getTimeInMillis()) {
              calendar.add(Calendar.DAY_OF_MONTH, 1);
          }
          alarmManager.cancel(pendingIntent);
          alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
  </code></pre>