AlarmManager 在特定设备上每秒添加几次警报
我的警报服务有问题 - 它被设置为每小时关闭一次,并且在我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PendingIntent.getService()
应传递一个标志 为其最后一个参数,而不是0
。我会先尝试解决这个问题。PendingIntent.getService()
should be passed a flag for its last parameter, not0
. I'd try fixing that first.