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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:41:02+00:00 2026-05-25T12:41:02+00:00

Below is my code for setting repeat alarm for daily. Now i need to

  • 0

Below is my code for setting repeat alarm for daily. Now i need to stop my alarm after 2 days. I tried to stop alarm after adding 2 days but it is not working . Please anyone help me.

Intent myIntent = new Intent(this, MyAlarmService.class);

    pendingIntent = PendingIntent.getService(this, (int) System.currentTimeMillis(), myIntent, 0); 

    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, hour1);
    calendar.set(Calendar.MINUTE, min1);
    calendar.set(Calendar.SECOND, 0);   

    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24*60*60*1000, pendingIntent);

    Toast.makeText(this, "Start Daily Alarm", Toast.LENGTH_LONG).show(); 

     //trying to cancel after 2 days
    // add days to current date using Calendar.add method 

    calendar.add(Calendar.DATE, 2);       
    pendingIntent = PendingIntent.getService(this, (int) System.currentTimeMillis(), myIntent, 0);
    AlarmManager alarmManagerstop = (AlarmManager)getSystemService(ALARM_SERVICE);
    alarmManagerstop.cancel(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-05-25T12:41:03+00:00Added an answer on May 25, 2026 at 12:41 pm

    here you pass the System time in milisecond in the 2nd parameter.

    PendingIntent.getService(this, (int) System.currentTimeMillis(), myIntent, 0);
    

    as in the 2nd parameter was the request code was pass so you have to do something like this.

    private static int REQUEST = 1;
    

    you have to keep this request code for each alarm you are set. Note if you pass this request code with same value then it’ll be override your alarm. so you have to pass the unique request code.

    For stop the alarm same request code was needed to find that PendingIntent object and pass to the alarm.cancel method like this way

    private static int REQUEST = 1;
    PendingIntent.getService(this, REQUEST, myIntent, 0);
    AlarmManager alarmManagerstop = (AlarmManager)getSystemService(ALARM_SERVICE);
    alarmManagerstop.cancel(pendingIntent); 
    

    and as you used System milisecond that was change in every milisecond so that request code also change frequently. To use this milisecond you can store in any static variable after that you can use same value.

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

Sidebar

Related Questions

I have the code below adding a movie clip to my stage and setting
I am setting background color of an li element by the code below :
I am using c# and jQuery. I have below code where I am setting
I have a problem with core data when setting relationships: The code below crashes
In my app, i am setting the Notification as like below code: // for
The code below draws a rectangle on every mouse move after the mouse button
Below code saying error incorreect syntax near Main INSERT INTO tbl ( 'Week', Main,
The below code is very simple. I have a jQuery autocomplete bound to an
My below code works fine and is used to populate a <select> item with
The below code works when there are a few element in the To list

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.