diff --git a/CHANGELOG.md b/CHANGELOG.md index fbc4a861..09caa8c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Fixed alarms not stopping when dismissed or snoozed after being deleted while ringing ([#406]) ## [1.6.0] - 2026-01-30 ### Added @@ -111,6 +113,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#247]: https://github.com/FossifyOrg/Clock/issues/247 [#335]: https://github.com/FossifyOrg/Clock/issues/335 [#346]: https://github.com/FossifyOrg/Clock/issues/346 +[#406]: https://github.com/FossifyOrg/Clock/issues/406 [Unreleased]: https://github.com/FossifyOrg/Clock/compare/1.6.0...HEAD [1.6.0]: https://github.com/FossifyOrg/Clock/compare/1.5.0...1.6.0 diff --git a/app/src/main/kotlin/org/fossify/clock/services/AlarmService.kt b/app/src/main/kotlin/org/fossify/clock/services/AlarmService.kt index 3d7b627b..dcfe3d2b 100644 --- a/app/src/main/kotlin/org/fossify/clock/services/AlarmService.kt +++ b/app/src/main/kotlin/org/fossify/clock/services/AlarmService.kt @@ -60,14 +60,25 @@ class AlarmService : Service() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { val action = intent?.action ?: ACTION_START_ALARM val alarmId = intent?.getIntExtra(ALARM_ID, -1) ?: -1 - val newAlarm = applicationContext.dbHelper.getAlarmWithId(alarmId) - if (alarmId == -1 || newAlarm == null) { + if (alarmId == -1) { stopSelfIfIdle() return START_NOT_STICKY } when (action) { - ACTION_START_ALARM -> startNewAlarm(newAlarm) + ACTION_START_ALARM -> { + // Starting requires the alarm to still exist in the DB. + val newAlarm = applicationContext.dbHelper.getAlarmWithId(alarmId) + if (newAlarm == null) { + stopSelfIfIdle() + return START_NOT_STICKY + } + + startNewAlarm(newAlarm) + } + + // Stopping only needs the id, so an alarm deleted while ringing + // can still be dismissed/snoozed. See issue #406. ACTION_STOP_ALARM -> stopActiveAlarm(alarmId) else -> throw IllegalArgumentException("Unknown action: $action") }