Search code examples
androidalarmmanager

Do I need to use AlarmManager.cancel() method?


I'm wondering - why do I need an AlarmManager.cancel() method, if I can just call cancel() method of corresponding PendingIntent and it would also work?


Solution

  • That's because the alarm and the pending intent are different things. Your alarm just triggers your pending intent at "x" time. If you cancel the pending intent but not your alarm then the alarm will be triggered anyway but the action will not occur because the pending intent is cancelled. Think of the alarm as the trigger and the pending intent as the action.