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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:49:22+00:00 2026-06-01T01:49:22+00:00

i have a problem with triggering the multiple alarm at first time , here

  • 0

i have a problem with triggering the multiple alarm at first time , here is my code

it is launcher activity where i write the following code ::

**onCreate Method :

// Calling Method setNextAlarm two times..with different id and time 

    setNextAlarm(0,60000);
    setNextAlarm(1,120000);

and the setNextAlarm is here ::

    private void setNextAlarm(int id,long time) {
            AlarmManager mgr = (AlarmManager) TestAct.this
            .getSystemService(Context.ALARM_SERVICE);
            Intent i = new Intent(TestAct.this, OnBootReceiver.class);
            i.putExtra("id", id);

            Log.e("Firing up next alarm in "+id,""+time/(60*1000) +"minutes");

            PendingIntent pi = PendingIntent.getBroadcast(TestAct.this, id, i,PendingIntent.FLAG_ONE_SHOT);
            mgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, time, pi);
   }

when i run this code it calls the onBootReceiver which is our Broadcast receiver class.

So My question is ::

After defining the different time and id in this method

setNextAlarm(0,60000);
setNextAlarm(1,120000);

why it fires at same time ? Except the first time it runs fine at fixed interval.

this is my onBootReceiver class’s onReceive method

Bundle b = intent.getExtras();  

int id = b.getInt("id");

if(id==1){
    PERIOD=300000;
}else{
    PERIOD=120000;
}

Log.e("OnBootReceiver"," Calling"+id+" in "+PERIOD/60000 + "minutes");

AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
   Intent i=new Intent(context, OnAlarmReceiver.class);
   i.putExtra("id", id);
   PendingIntent pi=PendingIntent.getBroadcast(context, id,i, 0);
   mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                      SystemClock.elapsedRealtime()+60000,
                      PERIOD,
                      pi);

Thanks.

  • 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-01T01:49:23+00:00Added an answer on June 1, 2026 at 1:49 am

    in OnBootReceiver

    mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                        SystemClock.elapsedRealtime() + 60000, PERIOD, pi);
    

    here is change

    i set

    SystemClock.elapsedRealtime() + 60000  for id = 0
    

    and set the

    SystemClock.elapsedRealtime() + 120000  for id = 1
    

    and the problem resolved.

    But i am still waiting for Better Explanation.

    i found little information here about SystemClock.elapsedRealtime()

    elapsedRealtime() is counted in milliseconds since the system was booted, including deep sleep. This clock should be used when measuring time intervals that may span periods of system sleep.

    http://developer.android.com/reference/android/os/SystemClock.html

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

Sidebar

Related Questions

I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
I have the problem that my code isn't triggering the action in my backing
I have a problem with onLocationChanged event in Android. Here's the triggering: case R.id.start:
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with fancybox. I want to write a function that will run
I'm having a problem triggering events on items that have been added to the
hi i have problem with logging, first i registered user in database,this works ok!
Here is a snippet of the code that creates a run time error Microsoft
I have the following code. (You can copy it into a file to debug
I have the following problem. I'm working on a simple jQuery tooltip and now

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.