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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:35:29+00:00 2026-06-01T03:35:29+00:00

I am calling an AsyncTask to stop an previously started service. But the ProgressDialog

  • 0

I am calling an AsyncTask to stop an previously started service.
But the ProgressDialog does not rotate while the Asyctask is running.
So I think that there is something wrong and I could get problems with an ANR error.

Any ideas?

new asyncTaskZieladresse().execute();

public class asyncTaskZieladresse extends AsyncTask<Void, Integer, Void> {
    int progress;
    @Override
    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        final Spinner Fahrerauswahl = (Spinner)findViewById(R.id.spinner1);
        final Spinner Fahrzeugauswahl = (Spinner)findViewById(R.id.spinner2);
        final Spinner Nutzungsartauswahl = (Spinner)findViewById(R.id.spinner3);
        Cursor mcursor = (Cursor) Fahrerauswahl.getSelectedItem();
        Fahrer = mcursor.getString(mcursor.getColumnIndexOrThrow("name"));
        FahrerID = mcursor.getString(mcursor.getColumnIndexOrThrow("_id"));
        mcursor.close();
        Cursor mcursor1 = (Cursor) Fahrzeugauswahl.getSelectedItem();
        Kennzeichen = mcursor1.getString(mcursor1.getColumnIndexOrThrow("fahrzeug_kennzeichen"));
        KennzeichenID = mcursor1.getString(mcursor1.getColumnIndexOrThrow("_id"));
        mcursor1.close();
        Cursor mcursor2 = (Cursor) Nutzungsartauswahl.getSelectedItem();
        Nutzungsart = mcursor2.getString(mcursor2.getColumnIndexOrThrow("nutzungsart"));
        NutzungsartID = mcursor2.getString(mcursor2.getColumnIndexOrThrow("_id"));
        mcursor2.close();
        VariablenUebergebenGpsFahrt();
        progressDialog.dismiss();
    }
    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        progressDialog = ProgressDialog.show(Main.this, "GPS", "Ziel-Standort wird ermittelt...");
    }
    @Override
    protected void onProgressUpdate(Integer... values) {
        // TODO Auto-generated method stub
    } 
    @Override
    protected Void doInBackground(Void... arg0) {
        // TODO Auto-generated method stub
        stopService(new Intent(Main.this, GPSService.class));
        return null;
    }    

}

  • 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-01T03:35:30+00:00Added an answer on June 1, 2026 at 3:35 am

    Thats the reason why I have tried to stop the service with the AsyncTask.

    This will not help, as I have tried to explain in the comments to your question. If onDestroy() is taking too long, you need to do that work sooner and in a background thread. Putting the stopService() call in a background thread is completely pointless.

    The service itself runs already in the background and not in the UI-thread.

    No, it is not.

    onDestroy() is called on the main application thread. Always.

    Your service might also have a background thread of its own for other work, but the lifecycle methods (onCreate(), onStartCommand(), onBind(), and onDestroy()) are always called on the main application thread.

    So if the stopping of the service took a long of time, why is the app hanging?

    Because you are doing too much work in onDestroy().

    The service and the command that waits for the return of the stopped service are not running in the UI-thread.

    onDestroy() is called on the main application thread (a.k.a., “UI-thread”).


    UPDATE based on first comment:

    When I call onDestroy() inside the service

    You never call onDestroy(). Android calls onDestroy(). You are not Android.

    the onDestroy() is not called inside the service for the service itself, rather in the Main thread?

    You seem to think that a service is a thread. It is not. You can tell this by reading the documentation (“Note that services, like other application objects, run in the main thread of their hosting process. “). Please read the documentation.

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

Sidebar

Related Questions

Calling image = Image.open(data) image.thumbnail((36,36), Image.NEAREST) will maintain the aspect ratio. But I need
Calling the ajax called URL works well without ajax eg. http://localhost/ci/controller/method/param_value . But using
When calling a remote service (e.g. over RMI) to load a list of entities
When calling php via cli, the current directory is NOT changed to the one
Inside of onPause, I'm calling cancel(true) on the AsyncTask called PlayTask. However, it still
Is it at all possible, from within an AsyncTask that is NOT an inner
Hello i am using AsyncTask for webservice calling. Its working fine when i enter
When calling AsyncTask<Integer,Integer,Boolean> , where is the return value of: protected Boolean doInBackground(Integer... params)
I am not sure what I am doing wrong but onPostExecute never gets called.
I have an asynctask of which's onPostExecute i am calling a function to show

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.