当我开始报警两次会发生什么? [英] What happens when I start an alarm twice?

查看:201
本文介绍了当我开始报警两次会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跳铁圈槽(当然,这并不是说复杂ofcourse),以避免启动报警两次。基本的code是这样的:

I'm Jumping trough hoops (well, it's not that complicated ofcourse) to avoid starting an alarm twice. The basic code goes like this:

AlarmManager mgr=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent i=new Intent(this, MyService.class);
PendingIntent pi=PendingIntent.getService(this, 0, i, 0);
mgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), AlarmManager.INTERVAL_FIFTEEN_MINUTES, pi);

难道问题,如果我实际上运行该code,每次我的应用程序启动?调用此约10倍,矫枉过正,实验时,我没有看到任何不良影响,但我找不到任何引用为这是巧合还是预期的行为。

Would it matter if I would actually run this code everytime my app starts? I'm not seeing any ill effects when calling this about 10 times as an overkill-experiment, but I can't find any reference as to if this is coincidence or expected behavior.

如果它不是特别预期的,感觉错误。它可能让我麻烦,如果以后的 AlarmManager 的行为变化。

If it is not especially expected, it feels 'wrong'. It might get me in to trouble later if the behavior of the AlarmManager changes.

推荐答案

由于对AlarmManager取消方法是细跟一个类似意图取消报警,我们可以说,该平台可识别特定的类名的意图。因此,调用此多次不应该是一个问题,因为该平台将知道,对于这样一个悬而未决的意图警报已经存在。

Since the cancel method for AlarmManager is fine with a 'similar' Intent to cancel the alarm, we can say that the platform recognizes the intent given the class name. Hence calling this repeatedly shouldn't be a problem since the platform will know that for such a pending intent an alarm already exists.

下面是一个<一个href=\"http://stackoverflow.com/questions/2844274/multiple-calls-to-alarmmanager-setrepeating-deliver-the-same-intent-pendingintent\">post ,讨论类似的东西。

Here is a post that talks something similar.

这篇关于当我开始报警两次会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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