如何正确地取消未决报警 [英] How to properly cancel pending alarms

查看:358
本文介绍了如何正确地取消未决报警的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法找到一个答案,但什么是标准传递匹配的PendingIntent 要从警报中删除?它,它基于像com.blah.package.myclass刚刚的名,或执行其他取值回事?

I can't seem to find an answer to this, but what is the criteria for passing in a matching PendingIntent to be removed from an alarm? It it based on the just the name like com.blah.package.myclass or do the Extras matter?

例如,我在做这样的事情,所有的报警火一样的意图:

For example, I'm doing something like this and all alarms fire the same intent:

    public void setAlarm(Context context, long nextAlarmMillis) {
        Intent intent = new Intent(context, AlarmReceiver.class);
        intent.putExtra("alarm", this);
        PendingIntent sender = PendingIntent.getBroadcast(context, 1234 /* unused */, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        // Get the AlarmManager service
        AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
        am.cancel(sender);
        am.set(AlarmManager.RTC_WAKEUP, nextAlarmMillis, sender);
    }

会发生什么事是,报警类可以被改变等,并传递作为其他。我取消previous报警,但我不知道,如果是做任何事或任何遗留的报警将保持不变。

What happens is that the Alarm class can be altered, etc and passed in as an Extra. I am canceling the previous alarm, but I'm not sure if it's doing anything or if any left over alarms will remain.

任何人都知道肯定?

推荐答案

以下是 AlarmManager 文件中所提及

任何报警,任何类型,其意图比赛这一个(由filterEquals定义(意图)),将被取消。

Any alarm, of any type, whose Intent matches this one (as defined by filterEquals(Intent)), will be canceled.

其中的<一个href=\"http://developer.android.com/reference/android/content/Intent.html#filterEquals%28android.content.Intent%29\"相对=nofollow> filterEquals()的定义是:

确定两个意图是意图分辨率(过滤)的目的是一样的。也就是说,如果它们的作用,数据类型,类,和类别是相同的。这不比较列入意图任何额外的数据。

Determine if two intents are the same for the purposes of intent resolution (filtering). That is, if their action, data, type, class, and categories are the same. This does not compare any extra data included in the intents.

我觉得最容易做的就是你保持的PendingIntent 传递给AlarmManager参考,并把它传递给取消。或者有一个工厂方法来构造这样的圆周率。

I think the easiest to do is you keep the reference of PendingIntent passed to AlarmManager, and pass it to cancel. Or have a factory method to construct such pi.

这篇关于如何正确地取消未决报警的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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