01
Dev.to Kotlin
作者:RYO ITABASHI
發布:09-04 08:21
I Still Can't Write Code. But I Finally Found Why the Alarm Fired and Nothing Happened.
The alarm fired, but the broadcast never reached the receiver, so the agent never started.
重點摘要
dumpsys alarm showed the alarm fired even though no app log appeared
On Android 14 with Samsung One UI, a broadcast receiver could fail silently after the app had been idle
Routing the alarm directly to a foreground service fixed the silent failure
The author revisits a puzzling Android bug: an alarm scheduled with AlarmManager appeared to fire, yet the app’s agent never started and produced no logs. By checking dumpsys alarm, they confirmed the OS delivered the alarm on time, but the broadcast receiver sometimes failed silently when the app process had been frozen in the background on Android 14 with Samsung One UI. The fix was to remove the receiver hop and send the PendingIntent directly to a foreground service. The post also notes additional safeguards needed for reliability, including a PARTIAL_WAKE_LOCK, boot-time rescheduling, disabling the job after repeated failures, and separating manual runs from scheduled alarms.
我还是不会写代码。但我终于找到了为什么闹钟响了却什么也没发生。
闹钟确实触发了,但广播没有成功送到接收器,代理程序因此没有启动。
重點摘要
通过 dumpsys alarm 确认系统确实在正确时间触发了闹钟
在 Android 14 和 Samsung One UI 上,广播接收器可能在后台冻结后静默失效
直接把 PendingIntent 指向前台服务,才能避开这个无声故障
作者回顾了一个棘手的 Android 问题:用 AlarmManager 设定的闹钟明明按时触发了,代理程序却完全没有启动,也没有任何日志。借助 dumpsys alarm,他确认系统确实按时发出了闹钟;真正出问题的是广播接收器,在应用长时间处于后台冻结状态时,Android 14 的 Samsung One UI 上可能静默收不到。解决办法是不再经过 receiver 中转,而是直接把 PendingIntent 指向前台服务。文章还提到,要让调度真正可靠,还需要部分唤醒锁、开机后重新设定、连续失败后自动停用,以及将手动运行与定时任务分开。
我還是不會寫程式。但我終於找到為什麼鬧鐘響了卻什麼也沒發生。
鬧鐘確實觸發了,但廣播沒有成功送到接收器,代理程式因此沒被啟動。
重點摘要
用 dumpsys alarm 確認系統確實在正確時間觸發了鬧鐘
在 Android 14 與 Samsung One UI 上,廣播接收器可能在背景凍結後靜默失敗
直接把 PendingIntent 指向前景服務,才能避免這個無聲故障
作者回顧一個難解的 Android 問題:AlarmManager 設定的鬧鐘看似準時觸發,但代理程式卻完全沒啟動,也沒有任何日誌。透過 dumpsys alarm,他確認系統確實送出了鬧鐘;真正失敗的是廣播接收器,在應用程式長時間待機、背景進程被凍結時,於 Android 14 的 Samsung One UI 上可能靜默收不到。解法是不再經由 receiver 中轉,而是直接把 PendingIntent 送到前景服務。文章也提到,為了讓排程真正可靠,還需要喚醒鎖、開機重排、連續失敗後自動停用,以及讓手動執行與排程任務彼此分離。