title: Triggering an alarm at a specific time every day by using setExact()
body: <p>I am trying to trigger an alarm once at a specific time everyday. But like all others I am using <code>setExact()</code> instead of <code>setRepeating()</code>. Alarm is firing at the correct time. But once it fires it keeps on repeating itself after every 5sec. How can I trigger it only once in a day at a specific time? Here is my code:</p>
  
  <p>MainActivity.java:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements Observer {
  
      private AlarmManager alarmManager = null;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          BroadcastObserver.getInstance().addObserver(this);
      }
  
      @Override
      public void update(Observable o, Object arg) {
          Log.e("MainActivity", "Alarm set through observer");
          cancelAlarm();
          setAlarm();
      }
  
      @Override
      protected void onStart() {
          super.onStart();
          if (!checkAlarm()) {
              setAlarm();
          }
  
      }
  
      public void setAlarm() {
          Calendar calendar = Calendar.getInstance();
          calendar.set(Calendar.HOUR_OF_DAY, 14);
          calendar.set(Calendar.MINUTE, 13);
          calendar.set(Calendar.SECOND, 0);
          alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
          Intent intent = new Intent(this, MyReceiver.class);
          intent.setAction(MyReceiver.ACTION_RECEIVER);
          PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1001, intent, PendingIntent.FLAG_CANCEL_CURRENT);
          alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
      }
  
      private boolean checkAlarm() {
          Intent intent = new Intent(this, MyReceiver.class);
          intent.setAction(MyReceiver.ACTION_RECEIVER);
          boolean isSet = PendingIntent.getBroadcast(this, 1001, intent, PendingIntent.FLAG_NO_CREATE) != null;
          Log.e("MainActivity", isSet + " :Alarm is set");
          return isSet;
      }
  
      @Override
      protected void onStop() {
          super.onStop();
          cancelAlarm();
      }
  
      private void cancelAlarm() {
          Intent intent = new Intent(this, MyReceiver.class);
          intent.setAction(MyReceiver.ACTION_RECEIVER);
          final PendingIntent pendingIntent =
                  PendingIntent.getBroadcast(MainActivity.this, 1001, intent,
                          PendingIntent.FLAG_NO_CREATE);
          if (pendingIntent != null) {
              alarmManager.cancel(pendingIntent);
              pendingIntent.cancel();
          }
      }
  }
  </code></pre>
  
  <p>BroadcastReceiver:</p>
  
  <pre><code>public class MyReceiver extends BroadcastReceiver {
  
      public static final String ACTION_RECEIVER = "Receiver";
  
      @Override
      public void onReceive(Context context, Intent intent) {
          Log.e("MainActivity", "triggered");
          BroadcastObserver.getInstance().updateValue(intent);
      }
  }
  </code></pre>
  
  <p>BroadcastObserver:</p>
  
  <pre><code>public class BroadcastObserver extends Observable {
      private static BroadcastObserver instance = new BroadcastObserver();
  
      public static BroadcastObserver getInstance(){
          return instance;
      }
  
      private BroadcastObserver(){}
  
      public void updateValue(Object data) {
          synchronized (this) {
              setChanged();
              notifyObservers(data);
          }
      }
  }
  </code></pre>