How to get and cancel a PendingIntent?

I have an alarmManager which I am using to send notifications to the user at specific times. Since there are multiple alarms, I have multiple pending intents that I am creating and giving a unique ID, However there are certain situations in which I will need to get all the pending intents and then cancel them, so I can reset the alarms. I have tried doing his and I still cant seem to get it right so I have a couple questions:

Is this how you would correctly get and cancel a PendingIntent?

Intent intent = new Intent(con, AppointmentNotificationReciever.class);
PendingIntent sender = PendingIntent.getBroadcast(con, id, intent,
        PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager) con.getSystemService(Context.ALARM_SERVICE);
am.cancel(sender);

Does the intent need to exactly match that of the original pending intent(extras and all)?

Does the PendingIntent flag need to match that of the original pending intent?

Answers


I found out that you do not actually "get" the pending intent...you have to recreate it exactly as it was when you first created it(Intent as well) and then pass it to the AlarmManager's cancel function. So the above code I posted really is not incorrect as long as thats how I first created it. Hopefully someone will find this helpful.


Need Your Help

SQL function to return “most common value” for multiple columns in a Group By

sql sql-server

I'm looking to find the simplest way to return the most common value in multiple column results of a select statement that is grouped. Everything I am finding online points to RANK on a single ite...

Problem with index server talking to remote server names with dashes or dots in them

indexing indexing-service

Hi I am having a problem, accessing a remote index server catalog. The name of the server has - in it, so i put the index catalog name as:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.