Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to cancel multiple alarms with duplicate PendingIntent at once?
    primarykey
    data
    text
    <p>I am setting multiple alarms which will have the exact same <code>PendingIntent</code> object, but their time of going off is different. If I cancel one alarm by providing the same <code>Intent</code> object to <code>PendingIntent</code>, and pass this to <code>AlarmManager.cancel()</code>, will it cancel all the alarms (i.e. with different starting times) or will it exhibit some other behavior? </p> <p>Here is the code:</p> <pre><code>while(size != 0) { timeToSet = getNewTime(); //gets calendar object Intent intent = new Intent(this, MyAlarmReceiver.class); intent.putExtra("uniqueid", uuid); intent.putExtra("vibrate", myalarm.getVibrate()); intent.putExtra("important", myalarm.getImportant()); PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | Intent.FILL_IN_DATA); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, timeToSet.getTimeInMillis(), 604800000, pendingIntent); size--; } </code></pre> <p>So the Intent object is same for all the alarms, but the time is different. Now when I cancel these alarms:</p> <pre><code>Intent intent = new Intent(this, MyAlarmReceiver.class); intent.putExtra("uniqueid", uuid); intent.putExtra("vibrate", myalarm.getVibrate()); intent.putExtra("important", myalarm.getImportant()); PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | Intent.FILL_IN_DATA); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.cancel(pendingIntent); </code></pre> <p>Will all the alarms get cancelled? That is what I want it to do. I could use a different <code>requestCode</code> in every <code>PendingIntent</code>, but it will be better if all of them get cancelled as I dont want to maintain and store these extra <code>requestCodes</code>.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload