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

  • Home
  • SEARCH
  • 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 8008011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:00:35+00:00 2026-06-04T18:00:35+00:00

My app needs to execute a specific task every hour. It does not matter

  • 0

My app needs to execute a specific task every hour. It does not matter if app is runing, suspended, or even closed.

When app is running or suspended, I can do it by just scheduling an AlarmManager broadcastreceiver. But when the application is closed, I have to call “unregisterReceiver” to not leak an intent, and app will never be wake up (or something) to process the task.

Then, the question is: how to schedule an alarmmanager task that I don’t need to unregister, so it will be called even if my application is closed?

  • 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-04T18:00:38+00:00Added an answer on June 4, 2026 at 6:00 pm

    Use AlarmManager.setRepeating(int type, long triggerAtTime, long interval, PendingIntent operation) for this. Set the type to AlarmManager.RTC_WAKEUP to make sure that the device is woken up if it is sleeping (if that is your requirement).

    Something like this:

        Intent intent = new Intent("com.foo.android.MY_TIMER");
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
        AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
        long now = System.currentTimeMillis();
        long interval = 60 * 60 * 1000; // 1 hour
        manager.setRepeating(AlarmManager.RTC_WAKEUP, now + interval, interval,
            pendingIntent); // Schedule timer for one hour from now and every hour after that
    

    You pass a PendingIntent to this method. You don’t need to worry about leaking Intents.

    Remember to turn the alarm off by calling AlarmManager.cancel() when you don’t need it anymore.

    Don’t register a Receiver in code for this. Just add an <intent-filter> tag to the manifest entry for your BroadcastReceiver, like this:

        <receiver android:name=".MyReceiver">
            <intent-filter>
                <action
                        android:name="com.foo.android.MY_TIMER"/>
            </intent-filter>
        </receiver>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running my C# application from D:\App\program.cs. My application needs to execute a
Our web app needs to be made PCI compliant, i.e. it must not store
Ive got a java app which needs to execute a driver installer exe file.
I need to run a task every hour on the hour (00:00, 01:00, 02:00,
I have a periodic task that needs to execute once a minute (using delayed_job).
I have a .exe program (console app) written in .net. I need to execute
The app needs to retrieve data from core-data then compare one of the values
My app needs to read .rtf file from URL. I am going to read
My app needs to be set in iOS 5 Notification Center as 'alerts' and
My app needs many NSStrings containing differente hard coded web URLs, to be accessed

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.