Is it possible to change the Intent
and it's extras each time AlarmManager
is triggered?
Asked
Active
Viewed 72 times
0

earthw0rmjim
- 19,027
- 9
- 49
- 63

atanti
- 57
- 7
-
1http://stackoverflow.com/questions/14106299/change-the-intent-of-pendingintent-which-is-used-by-an-alarmmanager check this out – Preetika Kaur Sep 15 '16 at 08:16
-
Tried the FLAG_UPDATE_CURRENT still didn't work. My goal is to just change the extras, no need for actions. – atanti Sep 15 '16 at 08:21
-
My I supposed to call the AlarmManager method each time ? – atanti Sep 15 '16 at 08:25
1 Answers
0
AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, Alarm.class);
// Extras aren't used to find the PendingIntent
PendingIntent pi = PendingIntent.getBroadcast(context, tag, i,
PendingIntent.FLAG_NO_CREATE); // find the old PendingIntent
if (pi != null) {
// Now cancel the alarm that matches the old PendingIntent
am.cancel(pi);
}
// Now create and schedule a new Alarm
i = new Intent(context, NewAlarm.class); // New component for alarm
i.putExtra("position", tag); // Whatever new extras
pi = PendingIntent.getBroadcast(context, tag, i, PendingIntent.FLAG_CANCEL_CURRENT);
// Reschedule the alarm
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ time, pi); // Millisec * Second * Minute
Yes everytime you need to cancel the current one and launch the new one if you want to make any changes in Intent like data extras, action , component anything.

Preetika Kaur
- 1,991
- 2
- 16
- 23
-
Will this run the new intent once it is fired, or do I need to call the method again ? – atanti Sep 15 '16 at 08:39
-
-
When you have to cancel the previous one so definitely you need to give call to method again to create new one. When you are firing alarm in that part of code give call to function. Try this hope it would help I am not much sure about this – Preetika Kaur Sep 15 '16 at 08:54