1

my question is how can I skip an alarm in Android.

I have created an alarm with a one-day interval. But the user can press a button to do the automatical work which is done after the interval, by himself.

So on the same day the automatical work shouldn`t be done again. But on the next day the alarm interval should work as before.

Can I handle this with the cancel-method? I think no. I think the cancel-method will cancel the whole alarm and not cancel only the next alarm.

How can I do it?

I hope you understand me. Sorry for my bad english.

Micha93
  • 628
  • 1
  • 9
  • 22

2 Answers2

0

You have to save your alarmId somewhere, when user completes his task all my himself than cancel your alarm by using your saved alarmId

For more details see Delete alarm from AlarmManager using cancel() - Android

Community
  • 1
  • 1
Haris Qurashi
  • 2,104
  • 1
  • 13
  • 28
  • I have this code in my programm... Log.i("LocalService", "Received start id " + startId + ": " + intent); Is it normal that the id is at first 1. And when the Service get called at second time 2 and at the third time 3. Or is this maybe the problem in my code? My problem is that the alarm never get canceled. I don't know why. – Micha93 Dec 12 '16 at 09:12
0

When the user presses the button to do whatever work manually, you should have it cancel your alarm all together and then restart a new alarm with this in your calendar start time object:

calendar.add(Calendar.DATE, 1);

That will make the alarm start at whatever time you already set, but not until the next day. As long as you reinstate your alarm with the same interval it will go back to working normal and will not fire off on the current day.

Nick Friskel
  • 2,369
  • 2
  • 20
  • 33