I set my alarm this way:
val broadcastReceiverIntent = Intent(context, AlarmReceiver::class.java)
broadcastReceiverIntent.putExtra(Constants.ALARM_INTENT_TIME, alarm.time)
broadcastReceiverIntent.putExtra(Constants.ALARM_INTENT_ID, alarm.id)
broadcastReceiverIntent.action = System.currentTimeMillis().toString()
val newPendingIntent = PendingIntent.getBroadcast(
context,
alarm.id?:0,
broadcastReceiverIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
//schedule alarm
val alarmClockInfo = AlarmManager.AlarmClockInfo(calendar.timeInMillis, null)
alarmManager.setAlarmClock(alarmClockInfo, newPendingIntent)
Then I cancel this way:
val broadcastReceiverIntent = Intent(context, AlarmReceiver::class.java)
val newPendingIntent = PendingIntent.getBroadcast(
context,
alarm.id?:0,
broadcastReceiverIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
alarmManager.cancel(newPendingIntent)
The alarm still fires off, even when I cancel it. The request code I used to set the alarm is thesame as the one I am using to cancel it.
What could be the cause?