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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:13:49+00:00 2026-06-07T05:13:49+00:00

In Android, I use the AlarmManager to set a repeating task that is executed

  • 0

In Android, I use the AlarmManager to set a repeating task that is executed once per day. The user can choose the time for this alarm. When he chooses 9:00 o’clock for example, a given task is executed every day at 9 o’clock, i.e. a pending intent is started that puts a notification to the notification bar.

Users of my app say that when their device was switched off at that time, there is no notification at all. Is it true that, when the device is off at the time when an alarm goes off, the alarm isn’t repeated after booting again?

If this is normal behaviour, how could that be circumvented? Should I write a shared preference (e.g. “last_execution_time”) in the IntentService that triggers the notification? And on boot-up, I can just check if the last execution has been more than 24 hours before, and if so, repeat it?

  • 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-07T05:13:52+00:00Added an answer on June 7, 2026 at 5:13 am

    Register broadcast receiver for intent with action android.intent.action.BOOT_COMPLETED, which would start the same task as you scheduled with AlarmManager (formerly ensuring that it was not fired in due time by AlarmManager).

    EDIT:
    for keeping track try sth like that (its just a tip – handle exact time around 9 securely on your own 😉

    public class KeepTrackReceiver extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
            SharedPreferences p = context.getSharedPreferences(
                    TrackedAlarmService.FILE_ALARM_TRACK, Context.MODE_PRIVATE);
            long lastAlarm = p.getLong(TrackedAlarmService.KEY_LAST_ALARM_MILLIS, -1L);
            if(lastAlarm == -1L || lastAlarm < TrackedAlarmService.getClosest9AM(false)) {
                context.startService(TrackedAlarmService.createIntent(context));
            }
    
        }
    }
    public class TrackedAlarmService extends IntentService {
    
        public static final String FILE_ALARM_TRACK = "alarmTrack";
        public static final String KEY_LAST_ALARM_MILLIS = "lastAlarmMillis";
    
        public static void schedule(Context context) {
            AlarmManager am = (AlarmManager) context.getSystemService(
                    Context.ALARM_SERVICE);
    
            PendingIntent pi = PendingIntent.getService(context, 0, 
                    createIntent(context), PendingIntent.FLAG_CANCEL_CURRENT);
    
            am.setRepeating(AlarmManager.RTC_WAKEUP, getClosest9AM(true), 
                    AlarmManager.INTERVAL_DAY, pi);
        }
    
        public static long getClosest9AM(boolean futurePastFlag) {
            Calendar c = Calendar.getInstance();
            c.setTimeInMillis(System.currentTimeMillis());
            if(futurePastFlag) {
                if(c.get(Calendar.HOUR_OF_DAY) > 9) {
                    c.roll(Calendar.DATE, true);
                }
            }
            else {
                if(c.get(Calendar.HOUR_OF_DAY) < 9) {
                    c.roll(Calendar.DATE, false);
                }
            }
            c.set(Calendar.HOUR_OF_DAY, 9);
            c.set(Calendar.MINUTE, 0);
            return c.getTimeInMillis();
        }
    
        public static Intent createIntent(Context context) {
            return new Intent(context, TrackedAlarmService.class);
        }
    
        public TrackedAlarmService() {
            super("TrackedAlarmService");
        }
    
        @Override
        protected void onHandleIntent(Intent intent) {
    
            //save last alarm time  
            getSharedPreferences(FILE_ALARM_TRACK, MODE_PRIVATE)
                .edit()
                .putLong(KEY_LAST_ALARM_MILLIS, System.currentTimeMillis())
                .commit();
    
            // Do your repeating job....
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I suspect there are applications on my Android system that use the AlarmManager way
I need that android application do something ant specific time of the day, for
In my Android app I have a service that is started via AlarmManager. I
Android's AlarmManager Javadoc states When an alarm goes off, the Intent that had been
In Android Alarm Manager, how can we schedule multiple alarms which are non-repeating and
I'm in the process of creating an android app that makes extensive use of
I have been trying to use Android's AudioManager.setMicrophoneMute() without much success. That is, it
Is it possible to query the Android AlarmManager for the time of the next
I have an Android application, which makes use of an AlarmManager to schedule events.
I use android-sdk-r12m-r17m-linux.zip and android-ndk-r8-linux-x86.tar.bz2 to compile my android apk. My compiling steps are:

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.