I have used the same pendingIntent to set multiple alarms using different intentId for each. the alarm is working. Now i want to cancel a particular alarm. If i use the cancel() method i would end up cancelling all the alarms. I want only a specific one to be deleted. Also the user should be able to cancel this alarm even during a second or a third launch. As in when i launch it the second time, i won't be having the same pendingIntent object. Would i have to persist the pendingIntent object? If so, how? and how do i cancel a single alarm from multiple alarms?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You can do it like this,
In your Pending Intent you can pass a
unique ID
in place ofrequestCode
And to cancel you can use the same unique ID to cancel it, using the same Pending Intent.
For getting more information you can just use StackOverflow or Google, for now I think
this answer
will do for you. :)Here is a kind of hack to do this with the explanation.
First of all you should create a unique intent for the pending intent. For this purpose you can create a custom data field of the intent for your application. I do this in the following way:
In your case
intentId
will be yours unique identifier of the intent.Then you create alarmManager notification as usual. To cancel an alarm you should do the following steps. At first you should create an intent as in the previous code sample. Then you create pending intent based on this intent (you also create the same pending intent for alarm). And then you cancel this alarm: