Marlonez
Marlonez

Reputation: 45

android alarms: Can alarm receiver cancel alarm after X repeats /

My android app allows the user to select an item and set an alarm on it. I'm trying to implement this with a repeating alarm, but I don't want the alarm to repeat forever. I want it to automatically be cancelled after 2 repeats. For example, the user selects an item and sets the alarm to 30 minutes. Thirty minutes later the alarm goes off (notification is delivered), but the user hasn't taken any action other than silence the alarm. Five minutes later the alarm is repeated if the user hasn't taken any action on the selected item. Another five minutes later the alarm is repeated if the user still hasn't taken any action.

If it gets to the second reminder, regardless of whether the user takes action or not, I'd like to cancel the alarm.

I'm pretty sure I can manage this outside of alarm receiver class, but is there a way within the class to determine how many times the alarm for a specific item has been called ? My alarm receiver class extends Service.

Thanks, -Mar

Upvotes: 0

Views: 260

Answers (1)

Donn Felker
Donn Felker

Reputation: 9651

Keep it simple and use a SharedPreference to store this counter. Increment on the alarm and then reset it when the alarm is set again.

Upvotes: 0

Related Questions