简体   繁体   中英

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

I want to ask about AlarmManager . When I need to cancel an alarm I must call cancel with the alarm's PendingIntent . So, is it possible to accidentally cancel an alarm that another app has set with the same id ? Also, how can I find all alarms set with AlarmManager by my app?

The alarms you create in your app are unique to your app and hence they can have same Ids used in another project/app.

There is no way to get all the alarms set in AlarmManager programmatically. 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.

As a rule of thumb, construct the pending intent as you did when you set the alarm and you'll cancel the right one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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