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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:52:41+00:00 2026-06-03T23:52:41+00:00

Recently I noticed strange behaviour when i tried to schedule Activities to be run

  • 0

Recently I noticed strange behaviour when i tried to schedule Activities to be run in the future using AlarmManager. Look at the code below, the first activity is started in 20 seconds, while the second activity is not started in 40 seconds instead it is started only after 60 seconds. Can anyone explain why the second intent doesn’t schedule the second activity to be called instead the third intent does. Does this mean that i can have only one intent for an activity in the AlarmManager.

//pending intent for morning
    Intent myIntent1 = new Intent(this, Activity1.class);
    pendingIntent1 = PendingIntent.getActivity(this, 0, myIntent1, 0);
    AlarmManager alarmManager1 = (AlarmManager)getSystemService(ALARM_SERVICE);
    Calendar calendar1 = Calendar.getInstance();
    //calendar1.set(Calendar.YEAR, Calendar.MONTH + 1, Calendar.DAY_OF_MONTH, morningTime, 0, 0);
    calendar1.setTimeInMillis(System.currentTimeMillis());
    calendar1.add(Calendar.SECOND, 20);
    alarmManager1.set(AlarmManager.RTC_WAKEUP, calendar1.getTimeInMillis(), pendingIntent1);

    //pending intent for noon
    Intent myIntent2 = new Intent(this, Activity2.class);
    pendingIntent2 = PendingIntent.getActivity(this, 0, myIntent2, 0);
    AlarmManager alarmManager2 = (AlarmManager)getSystemService(ALARM_SERVICE);
    Calendar calendar2 = Calendar.getInstance();
    //calendar2.set(Calendar.YEAR, Calendar.MONTH + 1, Calendar.DAY_OF_MONTH, noonTime, 0, 0);
    calendar2.setTimeInMillis(System.currentTimeMillis());
    calendar2.add(Calendar.SECOND, 40);
    alarmManager2.set(AlarmManager.RTC_WAKEUP, calendar2.getTimeInMillis(), pendingIntent2);

    //pending intent for night
    Intent myIntent = new Intent(this, Activity2.class);
    pendingIntent = PendingIntent.getActivity(this, 0, myIntent, 0);
    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
    Calendar calendar = Calendar.getInstance();
    //calendar.set(Calendar.YEAR, Calendar.MONTH + 1, Calendar.DAY_OF_MONTH, nightTime, 0, 0);
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.SECOND, 60);
    alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);'
  • 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-03T23:52:42+00:00Added an answer on June 3, 2026 at 11:52 pm

    Does this mean that i can have only one intent for an activity in the AlarmManager.

    No, but it means that you need distinct PendingIntents. You are calling:

    Intent myIntent = new Intent(this, Activity2.class);
    pendingIntent = PendingIntent.getActivity(this, 0, myIntent, 0);
    

    twice, and therefore the two getActivity() calls are returning the same PendingIntent.

    Either:

    • Use a different value for the 2nd parameter to getActivity(), or

    • Do something to the Intent objects to make them sufficiently different, such as using different action strings (note: extras are not sufficient)

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

Sidebar

Related Questions

I just recently noticed this behaviour. To put it shortly, it displays the commits
At my company we recently noticed that one developer was not using language files
I've been editing CSS using Firebug in Firefox, but recently noticed that Chrome is
I have recently noticed that my test code is too close to the production
I have been using Rstudio a great deal these days but recently noticed that
I recently inspect a GUI with Microsoft's Spy++ and noticed a strange structure; it
I recently noticed the following code which basically defines a class method public Func<string,
I've recently noticed some behaviour with the Visual Studio Designer (C#) that I don't
In one of my MVC3 web applications I have recently noticed some strange looking
I recently noticed lots of stores using the same URLS I cant seem to

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.