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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:57:37+00:00 2026-05-26T03:57:37+00:00

I am using this code to create an Alarm in a activity that can

  • 0

I am using this code to create an Alarm in a activity that can be launched by the user.

The Alarm sends an intent that launches a broadcast reciever and then a service.

private void setGameAlerts(){
                //Setting alarm to fire off NEW_GAME intent every 24 hours.
                 String alarm = Context.ALARM_SERVICE;
                Calendar calendar = Calendar.getInstance();

                calendar.set(Calendar.HOUR_OF_DAY, 8);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND,0);
                calendar.set(Calendar.MILLISECOND, 0);



                AlarmManager am = (AlarmManager)getActivity().getSystemService(alarm);
                    Intent intent = new Intent("NEW_ITEM");
                    PendingIntent sender = PendingIntent.getBroadcast(getActivity(), 0, intent, 0);

                    am.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis() , AlarmManager.INTERVAL_DAY, sender);

                     Log.e("RELEASE LIST", "ALARM Set For 1 day from " + calendar.getTimeInMillis());

For some reason EVERYTIME the activity is launched it Automatically sends this intent and the service is launched. is there something wrong with my code that is causing this to happen other than the alarm going off everyday at 8 oclock?

  • 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-26T03:57:38+00:00Added an answer on May 26, 2026 at 3:57 am

    It looks to me like you’re setting it for 8am TODAY, not 8am tomorrow. For example, if I run this code:

        Calendar calendar = Calendar.getInstance();
    
        calendar.set(Calendar.HOUR_OF_DAY, 8);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND,0);
        calendar.set(Calendar.MILLISECOND, 0);
    
        Log.i("Test", "Current time: " + System.currentTimeMillis() );
        Log.i("Test", "Calendar time: " + calendar.getTimeInMillis() );
    
        calendar.add(Calendar.DATE, 1);
    
        Log.i("Test", "Calendar time with a day added: " + calendar.getTimeInMillis() );
    

    I get the result:

    10-06 23:26:50.050: INFO/Test(8890): Current time: 1317968810056
    10-06 23:26:50.050: INFO/Test(8890): Calendar time: 1317913200000
    10-06 23:26:50.050: INFO/Test(8890): Calendar time with a day added: 1317999600000
    

    The calendar time is a number less than the current time, so therefore that calendar entry is in the past. It might make some sense that Android would immediately send the intent for an event that has past. If you add a day to it, or specify a date in your Calendar object, it should work.

    Note that this numerical dates are simply the standard Unix time with milliseconds added on. If you drop the last three digits and put the number into a Unix time converter, you’ll be able to check that the numbers you’re working with make sense. Eg: use 1317999600 with the Unix time converter and you’ll get 10am EST, which is 8am PST (my time zone).

    I hope that helps!

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

Sidebar

Related Questions

I'm using this code to create text in ArcMap. But I can't seem to
I am using this code to make the user input a name to create
I tried using this code inside Create() witch creates the listbox that contains the
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
I'm using PHP5 to create XML files. I have code like this: $doc =
i am trying to create slider movement graphics. The code explain better this. using
I've been using this code to create my UIWindow UIMyWindow* win = [[UIMyWindow alloc]
I am using this code to create a cookie with JQuery: $.cookie('MyCookieName', 'myValueHere'); It
i am using this code to create watermark. $image = '1.jpg'; $overlay = 'stamp.png';
I'm using this code to create a list of best selling items in Magento:

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.