I have this method to register/cancel alarms that I call from two different Activities - hence the context passed in is different each time.
I designed it so that the alertId in the Uri is the unique identifier for an alarm - all other parameters class, category are the same.
However, sometimes ActivityA might register an alarm with alertId = 1 by using its contextA in the pending intent. ActivityB might update the alarm with alertId = 1 by registering it again by using its contextB. Similarly with canceling the alarm.
Will the same alarm get updated?
Hence, I was wondering if there might be a side effect to having different contexts while registering an alarm with the same alertId. Does anyone have insight into this?
static void registerAlarm(Context context, Alert alert, Date alarmTime) {
// Get the AlarmManager Service
AlarmManager mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent mNotificationReceiverIntent;
PendingIntent mNotificationReceiverPendingIntent;
// Create PendingIntent to start the AlarmNotificationReceiver
mNotificationReceiverIntent = new Intent(context, NotifyActivity.class);
mNotificationReceiverIntent.setAction(Intent.ACTION_SENDTO);
// workaround from mazur - android bug database
Bundle hackbundle = new Bundle();
hackbundle.putParcelable(Alert.ALERT, alert);
mNotificationReceiverIntent.putExtra(Alert.ALERT, hackbundle);
mNotificationReceiverPendingIntent = PendingIntent.getBroadcast(context, 0,
mNotificationReceiverIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mNotificationReceiverIntent.setData(AlertsDbHelper.getUriForAlert(alert.alertId));
mAlarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime.getTime() + JITTER,
mNotificationReceiverPendingIntent);
Log.i(TAG, "registerAlarm() Alarm Set for alert id:" + alert.alertId + " alarm Time "
+ alarmTime);
Toast.makeText(context,
"Alarm Set for alert id:" + alert.alertId + " alarm Time " + alarmTime,
Toast.LENGTH_LONG).show();
}