android - Delete specific Alarm from AlarmManager -


i want delete alarm have set in broadcastreceiver. how should execute:

i receive gcm message, contains user_state field.

 if user_state 0 no notification triggered if user_state 1 notification triggered if user_state 2 alarm set , notification triggered 20 minutes later. 

this works well.

now want delete specific alarm, depending on data received gcm-intent. unfortunately alarmmanager.cancel() not compare fields. tried use intent.settype("data compare") if set field broadcast not received...

i have tried register new broadcastreceiver data should compared in action field. understand, should work fine, not possible register broadcastreceiver within broadcastreceiver.

also not possible list of pendingintents alarmmanager. can delete alarms - not option,

the other idea have using own service instead of alarmmanager... avoid one. don't want use resources when there buildin option.

here set alarm method:

private void settimed(intent intent, notify notify) {     bundle bundle = intent.getextras();     bundle.remove("userstate");     bundle.putstring("userstate", "3");      intent ringintent = new intent("de.pluetzner.waveobserver.treceive");     ringintent.settype(notify.gethost()+"&&&"+notify.getservice());     ringintent.putextras(bundle);     alarmmanager = (alarmmanager) this.context.getsystemservice(this.context.alarm_service);     pendingintent pi = pendingintent.getbroadcast(this.context, 0, ringintent, 0);     am.set(alarmmanager.rtc_wakeup, system.currenttimemillis() + (this.waittime * 60 * 1000), pi);     log.d("timer", "time set"); } 

the ringintent.settype() should identifier alarm not work. without alarm received

this 1 here method delete alarm.

private void deletealarm(intent intent, notify notify) {     intent ringintent = new intent("de.pluetzner.waveobserver.treceive");     ringintent.settype(notify.gethost() + "&&&" + notify.getservice());     pendingintent pi = pendingintent.getbroadcast(this.context, 0, ringintent, 0);     alarmmanager = (alarmmanager) this.context.getsystemservice(this.context.alarm_service);     am.cancel(pi);     log.d("timer", "time removed"); } 

it same here - settype set not work. without it, deletes every alarm.

i know somehow abusive use of settype - out of ideas. have any?

requestcode parameter of getbroadcast method uniquely identify each pendingintent.

you assign unique integer code each pendingintent.

alarm1:

      pendingintent pi = pendingintent.getbroadcast(this.context, 1, ringintent, 0);  

alarm2:

      pendingintent pi = pendingintent.getbroadcast(this.context, 2, ringintent, 0);  

now if want kill alarm2 alone, recreate pendingintent same identifier , call cancel method of alarmmanager

      pendingintent sender = pendingintent.getbroadcast(this, 2, intent, 0);       alarmmanager alarmmanager = (alarmmanager) getsystemservice(alarm_service);       alarmmanager.cancel(sender); 

Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -