0

I have written scheduler program in android using AlarmManager.i will start alarm using the below method.

    AlarmManager manager = (AlarmManager) getApplicationContext()
            .getSystemService(Context.ALARM_SERVICE);
    int interval = 1000 * 60 * initailDelay;
    manager.setInexactRepeating(AlarmManager.RTC_WAKEUP,
            System.currentTimeMillis(), interval, pendingIntent);
    Toast.makeText(getApplicationContext(), "Alarm Set", Toast.LENGTH_SHORT)
            .show();

Now i want to stop the alarm at given time?for example i have to start alarm at 6o'clock and end alarm at 6.30.

subash
  • 47
  • 11

1 Answers1

0

Add these lines :

AlarmManager manager = (AlarmManager) getApplicationContext()
        .getSystemService(Context.ALARM_SERVICE);
int interval = 1000 * 60 * initailDelay;
manager.setInexactRepeating(AlarmManager.RTC_WAKEUP,
        System.currentTimeMillis(), interval, pendingIntent);
Toast.makeText(getApplicationContext(), "Alarm Set", Toast.LENGTH_SHORT)
        .show(); 
manager.cancel(pendingIntent);
abhishesh
  • 3,246
  • 18
  • 20
  • for example i have to start alarm at 6o'clock and end alarm at 6.30 – subash Nov 18 '14 at 04:34
  • its not possible.... see this link, http://stackoverflow.com/questions/13196816/service-stopping-in-android –  Nov 18 '14 at 05:06
  • can you please help me to solve this https://stackoverflow.com/questions/51405397/cannot-cancel-the-current-alarm-in-android @abhishesh – Zhu Jul 23 '18 at 15:39