If you want to set several alarms (repeating or single), you just need to create their PendingIntent with different requestCode . If requestCode is the same, then the new alarm will overwrite the old one.
Here is the code for creating several single alarms and saving them in an ArrayList . I store the PendingIntent in an array, because this is what you need to cancel the alarm.
// context variable contains your `Context` AlarmManager mgrAlarm = (AlarmManager) context.getSystemService(ALARM_SERVICE); ArrayList<PendingIntent> intentArray = new ArrayList<PendingIntent>(); for(i = 0; i < 10; ++i) { Intent intent = new Intent(context, OnAlarmReceiver.class); // Loop counter `i` is used as a `requestCode` PendingIntent pendingIntent = PendingIntent.getBroadcast(context, i, intent, 0); // Single alarms in 1, 2, ..., 10 minutes (in `i` minutes) mgrAlarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 60000 * i, pendingIntent); intentArray.add(pendingIntent); }
Also see this question: How to set multiple alerts at once in android? .
Nikolai Samteladze 09 Oct 2018-12-12T00: 00Z
source share