title: How to pause and resume an Android Alarm?
body: <p>I am developping an alarm, which vibrates in time defined intervals. So if I choose 5 seconds, the app will vibrates at each 5 seconds intervals. But I need to stop, pause, and resume the app. </p>
  
  <p>This is my class:</p>
  
  <pre><code>public class AndroidAlarmService extends Activity {
  
  private PendingIntent pendingIntent;
  private Chronometer chronometer;
  private Intent myIntent;
  AlarmManager alarmManager;
  Calendar calendar;
  private long mTimeWhenStopped;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      Button buttonStart = (Button) findViewById(R.id.startalarm);
      Button buttonStop = (Button) findViewById(R.id.stopalarm);
      Button buttonPause = (Button) findViewById(R.id.pausealarm);
      Button buttonResume = (Button) findViewById(R.id.resumealarm);
  
      chronometer = ((Chronometer) findViewById(R.id.clock_time));
  
      myIntent = new Intent(AndroidAlarmService.this,
              MyAlarmService.class);
      pendingIntent = PendingIntent.getService(
              AndroidAlarmService.this, 0, myIntent, 0);
  
      alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
      calendar = Calendar.getInstance();
  </code></pre>
  
  <p>I start it in this method:</p>
  
  <pre><code>buttonStart.setOnClickListener(new Button.OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
  
              int initialValue = 0;
  
              chronometer.setBase(SystemClock.elapsedRealtime() + initialValue);
              chronometer.start();
  
              calendar.setTimeInMillis(System.currentTimeMillis());
  
              alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                      calendar.getTimeInMillis(), 5 * 1000, pendingIntent);
  
              Toast.makeText(AndroidAlarmService.this, "Start Alarm",
                      Toast.LENGTH_LONG).show();
          }
      });
  </code></pre>
  
  <p>This is used to pause:</p>
  
  <pre><code>    buttonPause.setOnClickListener(new Button.OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              stopRunning();
  
              mTimeWhenStopped = chronometer.getBase() - SystemClock.elapsedRealtime();
  
              // Tell the user about what we did.
              Toast.makeText(AndroidAlarmService.this, "Resume!",
                      Toast.LENGTH_LONG).show();
  
          }
      });
  </code></pre>
  
  <p>I'd like to resume the app from the point it has started.
  How can I do that?</p>
  
  <p>Thank, you!</p>