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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:43:01+00:00 2026-06-08T12:43:01+00:00

I have an Android application that has a service that runs in the background,

  • 0

I have an Android application that has a service that runs in the background, communicates with a remote server and displays notifications to users if needed. The app also has an activity for users to interact with.

One of the requirements is that the application needs to start itself automatically in the morning. At the end of the day the user is free to quit the app (Quit functionality stops the service, releases the wake lock, and lets Android kill the process). In order to automatically restart the application I am scheduling an alarm using AlarmManager and PendingIntent:

    //create intent to alert OnStartReceiver when alarm goes off
    Intent i = new Intent(context, OnStartReceiver.class);
    i.setAction("com.pointtrace.intents.alarm");
    i.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION|Intent.FLAG_FROM_BACKGROUND);


    //wrap inside PendingIntent so that it can be used from outside
    //our application
    PendingIntent pi = PendingIntent.getBroadcast(context, 1, i, PendingIntent.FLAG_ONE_SHOT);

    AlarmManager alarms = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);

    Log.d("GXT", "Scheduling alarm action(i)=" + i.getAction());

    //set alarm to go off at wake time
    alarms.set(AlarmManager.RTC_WAKEUP, getWakeTime(), pi);

OnStartReceiver class is registered to receive broadcasts and will restart the app when alarm occurs.

Everything works fine unless the user kills the application from Task Manager. If application is exited normally by either being killed by Android OS or my me calling System.exit(0); it restarts fine. But when it is killed from Task Manager is looks almost like alarm is getting cancelled.

I could not find anything in the Android documentation that would imply that alarms would be cancelled by Task Manager. Am I doing something wrong in regards to how to properly set the alarms?

I’ve tried removing the flags and just using 0 but it did not make any difference.

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-08T12:43:02+00:00Added an answer on June 8, 2026 at 12:43 pm

    Quit functionality stops the service, releases the wake lock, and lets Android kill the process

    If you are implying that you have a continuous WakeLock, unless this is only running on devices that are perpetually plugged in, your users will slap you with a trout.

    Also, Android can kill the process whenever it wants. Do not mistake startForeground() as some sort of guarantee that Android will never kill your process.

    But when it is killed from Task Manager is looks almost like alarm is getting cancelled.

    I have no idea what “Task Manager” is, since there is none in Android. If you mean the list of running apps in Settings, and clicking Force Stop, then yes, that cancels any outstanding alarms and prevents your app from ever running again until something manually starts one of your components (e.g., user launches your app from the launcher).

    Am I doing something wrong in regards to how to properly set the alarms?

    Probably not. Force-stop definitely wipes out your alarms.

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

Sidebar

Related Questions

I have an android application that has 3 activites. For the 1st and 2nd
I have an Android app that has an Application class and I have another
I have an Android app, that is using the SIM Toolkit. The application has
I have an android application that displays a toast every hour and then every
I have an android application that requres a login based on users in a
I have an Android application that has a need to perform work in the
I have a application in Android that has a broadcast receiver that clear any
I have developed an Android application that has 1 process and 2 services. But
Hello I have an android application which has a service running. After 20 mins
I'm developing an Android application that consists of: a lightweight background service that logs

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.