android - Canceling AlarmManager when notification is clicked -


i'm developing app uses setrepeating method send notification , want app cancel alarm manager when notification clicked (not swiped)..is there way that?

if not there way put button in notification same thing or must put button in app self cancel it?

this part use intent , alarmmanager

public void onclick(view v) {         intent = new intent(getapplicationcontext(), notifications.class);         pend = pendingintent.getbroadcast(getapplicationcontext(), 100, intent, pendingintent.flag_update_current);         = (alarmmanager) getsystemservice(alarm_service); am.setrepeating(alarmmanager.rtc_wakeup, calendar.gettimeinmillis(), 1000 * 60, pend); 

when notification clicked (not swiped)..is there way that?

yes, when issue notification have add alarm id pending intent:

intent notificationintent = new intent(context, notificationslandingactivity.class); notificationintent.putextra("alarm_id","123");  pendingintent pendingintent = pendingintent.getactivity(context, 0, notificationintent, pendingintent.flag_update_current); ... 

then, can fetch id savedinstancestate activity that's launched:

public class notificationslandingactivity extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          try {             string alarmid = getintent().getextras().getstring("alarm_id");             //cancel alarm         } catch (exception e) {             ...         }         ...     } } 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

Voice chat over bluetooth between Android & Python (pybluez) -

Integrate jquery-globalize into an ASP.NET Core MVC App -