AlarmManager 在特定设备上每秒添加几次警报

发布于 2024-12-27 04:43:54 字数 1257 浏览 1 评论 0原文

我的警报服务有问题 - 它被设置为每小时关闭一次,并且在我的 Galaxy SII 上运行得非常好 - 然而,在野火和野火 S 上,该应用程序占用了整个系统。 查看日志后,似乎每秒都会添加并触发几次警报。 我真的不明白为什么会发生这种情况,更让我困扰的是,这个问题怎么可能是设备特定的?

日志内容如下:

V/AlarmManager( 103): 添加警报{44cf66f8 type 0 weat.heria.app} Jan 12 04:43:35 pm V/AlarmManager( 103): 警报触发:Alarm{44cf66f8 type 0 weat.heria.app} V/AlarmManager( 103):添加闹钟{44cf66f8 type 0 weat.heria.app} Jan 12 04:43:35 pm V/AlarmManager( 103): 警报触发:Alarm{44cf66f8 type 0 weat.heria.app} V/AlarmManager( 103):添加闹钟{44cf66f8 type 0 weat.heria.app} Jan 12 04:43:36 pm V/AlarmManager( 103):警报触发:Alarm{44cf66f8 type 0 weat.heria.app}

请帮助我解决此问题。

编辑:这是设置闹钟的代码

 public void setAlarm(int refreshRate) {
     Intent myIntent = new Intent(WeatheriaActivity.this, AlarmService.class);
     pendingIntent = PendingIntent.getService(WeatheriaActivity.this, 0,
             myIntent, 0);
     AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
     Calendar calendar = Calendar.getInstance();
     calendar.setTimeInMillis(System.currentTimeMillis());
     calendar.add(Calendar.SECOND, 10);
     alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.
             getTimeInMillis(), refreshRate, pendingIntent);
}

I have got a problem with alarmservice - it's set up to go off every hour and it works perfectly fine on my galaxy SII - however, on the wildfire and wildfire S the app hogs the whole system.
After looking at logs, it seems that alarm is added and trigered a few times every second.
I really don't understand why this is happening and more than that it bothers me, how could this problem be device specifc?

Here is what the log says:

V/AlarmManager( 103): Adding Alarm{44cf66f8 type 0 weat.heria.app} Jan 12 04:43:35 pm
V/AlarmManager( 103): Alarm triggering: Alarm{44cf66f8 type 0 weat.heria.app}
V/AlarmManager( 103): Adding Alarm{44cf66f8 type 0 weat.heria.app} Jan 12 04:43:35 pm
V/AlarmManager( 103): Alarm triggering: Alarm{44cf66f8 type 0 weat.heria.app}
V/AlarmManager( 103): Adding Alarm{44cf66f8 type 0 weat.heria.app} Jan 12 04:43:36 pm
V/AlarmManager( 103): Alarm triggering: Alarm{44cf66f8 type 0 weat.heria.app}

Please help me regarding this.

Edit: here is the code setting the alarm

 public void setAlarm(int refreshRate) {
     Intent myIntent = new Intent(WeatheriaActivity.this, AlarmService.class);
     pendingIntent = PendingIntent.getService(WeatheriaActivity.this, 0,
             myIntent, 0);
     AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
     Calendar calendar = Calendar.getInstance();
     calendar.setTimeInMillis(System.currentTimeMillis());
     calendar.add(Calendar.SECOND, 10);
     alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.
             getTimeInMillis(), refreshRate, pendingIntent);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弱骨蛰伏 2025-01-03 04:43:54

PendingIntent.getService() should be passed a flag for its last parameter, not 0. I'd try fixing that first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文