警报-一段时间后停止鸣响 [英] android - Alarm stops firing after some time

查看:101
本文介绍了警报-一段时间后停止鸣响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 .

这是您可以参考的示例.

这篇关于警报-一段时间后停止鸣响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆