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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:19:33+00:00 2026-05-31T06:19:33+00:00

I have a Service which does regular operations such as Bluetooth discovery and sending

  • 0

I have a Service which does regular operations such as Bluetooth discovery and sending emails. Depending on the state, it starts different threads which does Bluetooth socket connection or send emails. I’m using AsyncTask to do email sending and it is working well at the moment.

The question I have is this: does AsyncTask I started from the Service finish when Service is stopped, or is the Service not stopped until AsyncTask completes? Under normal circumstances the Service is never ‘stopped’, but it can be stopped when the memory is low, or when the battery is low, or when the phone turns off. I need to resume the operation after the Service is stopped, and I’m wondering how to tell if AsyncTask has completed when the Service is stopped.

I have included a snapshot of my code.

public class ScheduledService extends Service {
    SendEmailAsyncTask emailTask;
    boolean emailSuccess;

    @Override
    public int onStartCommand(Intent intent, int flag, int startId) {
        log.v("onStart()");
        super.onStartCommand(intent, flag, startId);
        // do regular operations

        if (state == sendEmail) {
            emailTask = new SendEmailAsyncTask();
            emailTask.execute();
        }
    }


    class SendEmailAsyncTask extends AsyncTask <Void, Void, Boolean> {

        @Override
        protected Boolean doInBackground(Void... params) {
            // send email
        }

        @Override
        protected void onPostExecute(Boolean result){
            if (result) {
                createNotification("Email has been sent!");
                emailSuccess = true;
            } else {
                //try again
                emailSuccess = false;
            }
        }       
    }
}
  • 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-31T06:19:34+00:00Added an answer on May 31, 2026 at 6:19 am

    the task won’t stop if its doing something and in between the service is stopped. Unless you call task’s cancel method in service’s onDestroy’s implementation, it will be ended only once completed

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

Sidebar

Related Questions

I have an ASP.NET web service which does some heavy lifting, like say,some file
I have a dedicated server which hosts a Windows Service which does a lot
I have created a ASMX Web Service which does some Active Directory stuff behind
I have some service which does some file processing. It may need to map
I have created a WCF service which does not use the app.config to configure
I have a WCF 4 REST service which does some processing and then returns
suppose i have a windows service which does some work and developed by c#.
I have a background service which sets a repeating alarm, does its task and
I have created a service which would show Hello World message when it starts..
I have a basic windows service which does some conversions of data. There's decoupled

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.