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

  • Home
  • SEARCH
  • 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 8658707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:50:03+00:00 2026-06-12T15:50:03+00:00

I use AlarmManager to schedule multiple taks, i.e. Task 1 at 10:56, Task 2

  • 0

I use AlarmManager to schedule multiple taks, i.e. Task 1 at 10:56, Task 2 at 11:24 and so on.
Here’s the code:

  intent = new Intent(ACTION_RECORDER_START);
  intent.putExtra(EXTRA_COMMAND_ID, command.id);
  pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
  alarmManager.set(AlarmManager.RTC_WAKEUP, command.start, pendingIntent);

Here’s the strange thing: If I set one alarm, it does job well. If I set two, only the last alarm is fired.
So, I guess the problem is that when I set second, third…alarm, previous is overriden.

From developer docs:

If there is already an alarm for this Intent scheduled (with the
equality of two intents being defined by filterEquals(Intent)), then
it will be removed and replaced by this one.

I went to the sources, here’s the implementation of that method:

public boolean filterEquals(Intent other) {
        if (other == null) {
            return false;
        }
        if (mAction != other.mAction) {
            if (mAction != null) {
                if (!mAction.equals(other.mAction)) {
                    return false;
                }
            } else {
                if (!other.mAction.equals(mAction)) {
                    return false;
                }
            }
        }
        if (mData != other.mData) {
            if (mData != null) {
                if (!mData.equals(other.mData)) {
                    return false;
                }
            } else {
                if (!other.mData.equals(mData)) {
                    return false;
                }
            }
        }
        if (mType != other.mType) {
            if (mType != null) {
                if (!mType.equals(other.mType)) {
                    return false;
                }
            } else {
                if (!other.mType.equals(mType)) {
                    return false;
                }
            }
        }
        if (mPackage != other.mPackage) {
            if (mPackage != null) {
                if (!mPackage.equals(other.mPackage)) {
                    return false;
                }
            } else {
                if (!other.mPackage.equals(mPackage)) {
                    return false;
                }
            }
        }
        if (mComponent != other.mComponent) {
            if (mComponent != null) {
                if (!mComponent.equals(other.mComponent)) {
                    return false;
                }
            } else {
                if (!other.mComponent.equals(mComponent)) {
                    return false;
                }
            }
        }
        if (mCategories != other.mCategories) {
            if (mCategories != null) {
                if (!mCategories.equals(other.mCategories)) {
                    return false;
                }
            } else {
                if (!other.mCategories.equals(mCategories)) {
                    return false;
                }
            }
        }

        return true;
    }

So, as far as I see, no mention of extras. In fact, I was relying on this:

intent.putExtra(EXTRA_COMMAND_ID, command.id);

but standart implementation doesn’t compare exras.
So, when I schedule multiple intents, they are compared equal and get overriden!

The actual question:

How do I override filterEquals(Intent), so that I can distinguish Intents based on Extras?

Here’s my implementation:

 static class AlarmIntent extends Intent{

        public AlarmIntent(String action){
            super(action);
        }

        @Override
        public boolean filterEquals(Intent other){
            if(super.filterEquals(other)){
                long id  = getExtras().getLong(AudioRecorder.EXTRA_COMMAND_ID, -1);
                long otherId = other.getExtras().getLong(AudioRecorder.EXTRA_COMMAND_ID, -1);
                if(id == otherId){
                    return true;
                }
            }
            return false;
        }
    }

But it seems to me it doesn’t work. I think that overriden filterEquals is not called.

  • 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-06-12T15:50:05+00:00Added an answer on June 12, 2026 at 3:50 pm

    Ended up with this:

    pendingIntent = PendingIntent.getService(context, UNIQUE_ID, intent, PendingIntent.FLAG_ONE_SHOT);
    

    Providing second argument to getService did the job.

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

Sidebar

Related Questions

I have an Android application, which makes use of an AlarmManager to schedule events.
In Android, I use the AlarmManager to set a repeating task that is executed
use Text::Table; my $tb = Text::Table->new(Planet,Radius\nkm,Density\ng/cm^3); $tb->load( [ Mercury,2360,3.7], [ Mercury,2360,3.7], [ Mercury,2360,3.7], );
use LWP::UserAgent; use Data::Dumper; my $ua = new LWP::UserAgent; $ua->agent(AgentName/0.1 . $ua->agent); my $req
I have this code Calendar c = new GregorianCalendar(); c.add(Calendar.DAY_OF_YEAR, 1); c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE,
I'm trying to schedule on Android a specific part of my code to be
When setting a service to go off at particular time, I use the AlarmManager
Android's AlarmManager Javadoc states When an alarm goes off, the Intent that had been
I suspect there are applications on my Android system that use the AlarmManager way
In Android Alarm Manager, how can we schedule multiple alarms which are non-repeating and

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.