android - How to cancel a PendingIntent when is set to repeating? -


i have this...

button = (button) findviewbyid(r.id.start_repeating); button.setonclicklistener(new onclicklistener() {     public void onclick(view v) {         intent intent = new intent(test.this, repeatingalarm.class);         pendingintent sender = pendingintent.getbroadcast(test.this, 0, intent, 0);         long firsttime = systemclock.elapsedrealtime();         firsttime += 1 * 1000;         alarmmanager = (alarmmanager) getsystemservice(alarm_service);         am.setrepeating(alarmmanager.elapsed_realtime_wakeup, firsttime, 1 * 1000, sender);         if (mtoast != null) {             mtoast.cancel();         }         mtoast = toast.maketext(test.this, "repeating_scheduled", toast.length_long).show();     } });  button = (button) findviewbyid(r.id.stop_repeating); button.setonclicklistener(new onclicklistener() {     public void onclick(view v) {         intent intent = new intent(test.this, repeatingalarm.class);         pendingintent sender = pendingintent.getbroadcast(test.this, 0, intent, 0);         alarmmanager = (alarmmanager) getsystemservice(alarm_service);         am.cancel(sender);         if (mtoast != null) {             mtoast.cancel();         }         mtoast = toast.maketext(test.this, "repeating_unscheduled", toast.length_long).show();     } }); 

but doesn't seems work properly... each time try clicking second button alarm doesn't cancel... broadcastreceiver i'm using...

public class repeatingalarm extends broadcastreceiver {     @override     public void onreceive(context context, intent intent) {         for(int i=0;i<5;i++)             toast.maketext(context, "repeating_received " + i, toast.length_short).show();     } } 

please tell me wrong!!! thanks!!

if save reference pending intent can use alarmmanager.cancel().

pass in pending intent , set.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -