I wrote an app to turn on/off WiFi at scheduled time choosen before. The way it works is preety simple: Choose time from timepicker, then just add it. Programmatically it gets d
When you set an alarm, you pass a PendingIntent
to AlarmManager
. The PendingIntent
wraps an Intent
. When you set an alarm, AlarmManager
deletes any alarms it already has scheduled that match the PendingIntent
. To determine if the PendingIntent
s match, the following are compared:
requestCode
in the PendingIntent.getBroadcast()
callIntent
Intent
Intent
Component
(package name, class name) in the Intent
NOTE: "extras" in the Intent
are not compared
So, if we want to reschedule an alarm, you just need to create a PendingIntent
with the same requestCode
, ACTION and Component
as the previous one and set the alarm again. AlarmManager
will remove the previous one and set the new one.
If you want to have multiple alarms scheduled in parallel, you need to ensure that either the requestCode
s, the Component
s or the ACTIONs are different, otherwise they will overwrite each other.