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 6328987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:33:50+00:00 2026-05-24T17:33:50+00:00

I am using the alarmManager to set up multiple alarms within my application and

  • 0

I am using the alarmManager to set up multiple alarms within my application and have run into an issue. When setting the PendingIntent this way:

timerAlarmIntent = PendingIntent.getBroadcast(myContext, 0, alarmIntent, 0);
myAM.set(AlarmManager.RTC_WAKEUP, alarmTime, timerAlarmIntent);

Where the requestCode is set to 0 (beside the context in getBroadcast) I can use:

myAM.cancel(timerAlarmIntent);

to cancel any amount of alarms I set in the application. However, each alarm I set overwrites the last so only one alarm ends up going off. If I set the requestCode to a unique number such as:

timerAlarmIntent = PendingIntent.getBroadcast(myContext, i, alarmIntent, 0);
myAM.set(AlarmManager.RTC_WAKEUP, alarmTime, timerAlarmIntent);

Where i is set to a unique id number for each alarm using a for loop. This way all alarms run fine, but I cannot cancel the alarms because only one alarm will actually cancel when I run:

myAM.cancel(timerAlarmIntent);

How do I set the requestCode to a unique number and also have the option to cancel it?

The code I ended up using to solve the problem is:

timerAlarmIntent = PendingIntent.getBroadcast(myContext, i, alarmIntent, 0);
ArrayList<PendingIntent> intentArray = new ArrayList<PendingIntent>();
intentArray.add(timerAlarmIntent);
myAM.set(AlarmManager.RTC_WAKEUP, alarmTime, timerAlarmIntent);

To cancel the PendingIntents I set up the following method:

    private void cancelAlarms(){
    if(intentArray.size()>0){
        for(int i=0; i<intentArray.size(); i++){
            myAM.cancel(intentArray.get(i));
        }
        intentArray.clear();
    }
}
  • 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-24T17:33:51+00:00Added an answer on May 24, 2026 at 5:33 pm

    Why don’t you store timerAlarmIntent objects in a list and cancel them in a loop when needed ?

    Regards,
    Stéphane

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

Sidebar

Related Questions

I have created a Alarm using AlarmManager. Intent intent = new Intent(MyApp.this,NotificationMessage.class); PendingIntent sender
How to set Alarm Tone from My Application using AlarmManager? My RingTonePicker Method:- private
I have an application, which sets an alarm using AlarmManager, which starts another Activity
I am setting an alarm using an AlarmManager. The AlarmManager is set with the
Using online interfaces to a version control system is a nice way to have
I have an application that calls AlarmManager Intent intent; intent = new Intent(context, MyEventReceiver.class);
I have a question on scheduling an event using AlarmManager with ELAPSED_REALTIME. I want
I have this piece of code that fire the alarm once by setting a
I am using AlarmManager and NotificationManager with BroadcastReceiver . When I set an alarm
I'm doing one application like raising email intent by time using AlarmManager . In

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.