Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7408619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:56:52+00:00 2026-05-29T05:56:52+00:00

I am creating a repeating alarm. This works fine using the following code: Intent

  • 0

I am creating a repeating alarm. This works fine using the following code:

Intent intent = new Intent(this.ctx, AlarmReceiver.class);
intent.setAction("" + notificationId);
intent.putExtra(AlarmReceiver.TITLE, alarmTitle);
intent.putExtra(AlarmReceiver.SUBTITLE, alarmSubTitle);
intent.putExtra(AlarmReceiver.TICKER_TEXT, alarmTicker);
intent.putExtra(AlarmReceiver.NOTIFICATION_ID, notificationId);

 PendingIntent sender = PendingIntent.getBroadcast(this.ctx, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
 AlarmManager am = getAlarmManager();
 am.setRepeating(AlarmManager.RTC_WAKEUP, triggerTime, 60000, sender);

Now I want to cancel an existing notification message (which pops up every minute for testing purposes), I invoke the following code, passing it an identical notificationId:

Intent intent = new Intent(this.ctx, AlarmReceiver.class);
intent.setAction("" + notificationId);
PendingIntent pi = PendingIntent.getService(this.ctx, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

     AlarmManager am = getAlarmManager();
     try {
          am.cancel(pi);

         } catch (Exception e) {
       Log.e(PLUGIN_NAME, "AlarmManager update was not canceled. " + e.toString());
}

I see that pi != null, however the notification keeps coming and is not being cancelled. Both code snippets reside in the same class.

Basically I have two questions:
– How can I cancel a single alarm using its unique ID?
– How can I cancel all alarms, regardless of the ID?

UPDATE: I found that posting my issue here helps to get my mind straight. Changing the cancel code from:

PendingIntent sender = PendingIntent.getService( ... )

To:

PendingIntent sender = PendingIntent.getBroadcast( ... )

Helps to solve question 1. However the code to cancel all events, still does not work:

Intent intent = new Intent(this.ctx, AlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(this.ctx, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

AlarmManager am = getAlarmManager();
am.cancel(pi);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:56:53+00:00Added an answer on May 29, 2026 at 5:56 am

    I’m a noob here. But I think if you want to cancel the alarm, you have to use the exact same instance of PendingIntent. That means “their action, data, type, class, and categories are the same” as defined by filterEquals(Intent) . Therefore, you need to use the same requestCode here, not 0. Maybe you could use a list to store the Notification Ids, and iterate them to cancel all alarms.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
We're using Quartz.Net to schedule about two hundred repeating jobs. Each job uses the
I need to generate a vector of the following format using R: 1:10, 1:10,
I'm using the NPOI library with a C# application. What I'm creating is a
I am creating a iphone game currently using cocos2d. The basics of the game
I've seen a few questions here and there about creating event log sources using
Is this possible? I am creating a an object from a JSON string with
I'm creating a reporting application, and our customers are going to need to generate
When creating a subscription on reporting services 2008 one is unable to select all
I'm releasing an application I wrote as an open-source project by creating a public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.