简体   繁体   English

出于警报管理器的目的,未决意图对于应用程序或设备是否具有唯一的ID?

[英]For purposes of Alarm Manager, does a pendingintent have unique id for app or for device?

I want to ask about AlarmManager . 我想问一下AlarmManager When I need to cancel an alarm I must call cancel with the alarm's PendingIntent . 当我需要取消警报时,必须使用警报的PendingIntent调用cancel。 So, is it possible to accidentally cancel an alarm that another app has set with the same id ? 因此,是否可能会意外取消另一个应用程序已设置相同id的警报? Also, how can I find all alarms set with AlarmManager by my app? 另外,如何找到我的应用程序使用AlarmManager设置的所有警报?

The alarms you create in your app are unique to your app and hence they can have same Ids used in another project/app. 您在应用程序中创建的警报对于您的应用程序是唯一的,因此它们可以具有在另一个项目/应用程序中使用的相同ID。

There is no way to get all the alarms set in AlarmManager programmatically. 无法以编程方式获取在AlarmManager中设置的所有警报。 You will have to maintain a list of alarms you set in preferences or in database. 您将必须维护在首选项或数据库中设置的警报列表。

For cancellation, the PendingIntent is identified by the contained Intent according to filterEquals , which checks for "action, data, type, class, and categories", but doesn't look at the intent's extras. 对于取消,PendingIntent由根据filterEquals包含的Intent进行标识 ,该filterEquals检查“动作,数据,类型,类和类别”,但不查看该Intent的额外内容。

As a rule of thumb, construct the pending intent as you did when you set the alarm and you'll cancel the right one. 根据经验,应像设置警报时一样构造挂起的意图,然后取消正确的意图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM