Skip to content Skip to sidebar Skip to footer

How I Can Cancel An Alarm After A Period Of Time? | Android

hi i have an alarm here and i want a way to cancel it AFTER a period of time like a day for example or a week ,,, and thanks in advance ,, am = (AlarmManager)parent.getContext

Solution 1:

try

finalPendingIntentsender= PendingIntent.getBroadcast(parent.getContext(), CountMultipleAlarm,
                                     alarmintent,0);
int someTime=1000;

newHandler().postDelayed(newRunnable()
{
    publicvoidrun()
    {
     am.cancel(sender);
    }
}, someTime);

Solution 2:

Set a second alarm that cancels the first alarm.

Solution 3:

You have already set an alarm once, so you know how to do it. The key is to set a second alarm, whose purpose is to end the original alarm. The difficult part is finding the original alarm to cancel, however, you can just execute this code upon your second alarm to cancel the first, using the cancel pending intent. This code, as Android docs specify, will cancel all alarms with the same class. Thus, you only need to create an intent, pass it to the AlarmManager, and you can cancel the alarm.

Intentalarmintent=newIntent(parent.getContext(), Alarm_Receiver.class);
PendingIntentsender= PendingIntent.getBroadcast(parent.getContext(), CountMultipleAlarm,
                                 alarmintent,0);
am.cancel(sender);

Post a Comment for "How I Can Cancel An Alarm After A Period Of Time? | Android"