警报

编程入门 行业动态 更新时间:2024-10-28 08:21:56
本文介绍了警报-一段时间后停止鸣响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个警报,每小时触发一次,并在特定条件下执行代码它可以正常运行,但是当我未打开我的应用程序时(警报初始化是在应用程序启动时启动),一段时间后它停止了,这些是日志:

I have an alarm that fires every hour and executes code in specific conditions It works smoothly, but when I leave my app unopened (the alarm initialization is on app startup) it stops after some time, these are the logs:

8/2/2020 6:27 AM Initializing Alarm, next alarm will fire at 8/2/2020 3:27 AM 8/2/2020 6:27 AM Application starting. 8/2/2020 6:28 AM Application stopped. 8/2/2020 6:28 AM Reports alarm received. 8/2/2020 7:28 AM Reports alarm received. 8/2/2020 8:28 AM Reports alarm received. 8/2/2020 9:28 AM Reports alarm received. 8/2/2020 9:28 AM Reports alarm finished. 8/2/2020 10:28 AM Reports alarm received. 8/2/2020 10:28 AM Reports alarm finished. 8/2/2020 11:28 AM Reports alarm received. 8/2/2020 11:28 AM Reports alarm finished. 8/2/2020 12:30 PM Reports alarm received. 8/2/2020 12:30 PM Reports alarm finished. 8/2/2020 1:30 PM Reports alarm received. 8/2/2020 1:30 PM Reports alarm finished. 8/2/2020 2:30 PM Reports alarm received. 8/2/2020 2:30 PM Reports alarm finished. 8/3/2020 8:13 AM Initializing Alarm, next alarm will fire at 8/3/2020 5:13 AM

您看到第二天的下午2:30到8:13之间没有警报发出

As you see between 2:30 PM to 8:13 AM the next day, no alarms were fired

这是初始化:

alarmMgr.SetInexactRepeating(AlarmType.RtcWakeup, calendar.TimeInMillis, 1000 * 60 * 60, alarmIntent);

我已获得WAKE_LOCK权限.

I have acquired the WAKE_LOCK permission.

预先感谢

推荐答案

当应用程序在前景或后台运行时,AlarmManager可以完美运行.

AlarmManager work perfectly when the App is running in Foreground or in Background.

但是当应用退出/强制停止/被杀死时,警报管理器将被取消.

But when the App is quit/force-stopped/killed , Alarm Manager is cancelled.

只有用户再次启动该应用程序时,警报才会再次发出.

Alarm will go off again only the App is again launched by the user.

要在应用程序关闭时使警报保持活动状态,您可能必须使用前台服务.

To keep alarm alive when app closed you might have to use Foreground service .

这是您可以参考的示例.

更多推荐

警报

本文发布于:2023-11-27 02:04:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636119.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!