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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:14:09+00:00 2026-06-15T15:14:09+00:00

The progress dialog in AsyncTask does not dismiss, even though progressDialog.dismiss is run in

  • 0

The progress dialog in AsyncTask does not dismiss, even though progressDialog.dismiss is run in onPostExecute().

I have tried implementing many answers to related questions on SO, with no success so far.

I am sure that I must be overlooking something very basic, but I am stuck.

Any pointers to an explanation and code snippet would be great, Thanks.

Main

public class Main extends Activity {
    String result;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        asyncTask task = new asyncTask("Loading ...", this);
        try {
            result = task.execute("Question").get();
        }
        catch (Exception e) {
            Log.e("Error: ", e.toString());
        }
    }
}

asyncTask

public class asyncTask extends AsyncTask<String, Void, String> {

    private ProgressDialog progressDialog;
    private String message;
    private Context context;

    public asyncTask(String msg, Context ctx) {
        this.context = ctx;
        message = msg;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        progressDialog = new ProgressDialog(context);
        progressDialog.show(context, "", message, true, false);
    }

    @Override
    protected String doInBackground(String... params) {
        int count = 100000;
        for (int i = 0; i < count; i++) {
           // waste time
        }
        return "Answer";
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        progressDialog.dismiss();
    }
}
  • 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-15T15:14:10+00:00Added an answer on June 15, 2026 at 3:14 pm

    Actually your are doing :

    progressDialog.show(context, "", message, true, false);
    

    instead it should be like :

    progressDialog = ProgressDialog.show(context, "", message, true, false);
    

    You have to statically call show method and assign it to your progressDialog

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

Sidebar

Related Questions

i have used asynctask in my programme i have dismiss dialog before intent is
I've developed a simple asynctask with progressdialog attached to it, to show progress of
I'm using AsyncTask to update a horizontal Progress Dialog. There are no errors. The
I am using AsyncTask to download files. There i implemented progress: //Updating progress dialog
I am trying to have a a progress dialog open when polling my server.
I have a Async Task that does not add the percentage while it is
I have the question about using the AsyncTask with the ProgressDialog.There is the exception
I have an AsyncTask which does a lot of JSON calculations. public class InitializationTask
I need to update a progress dialog fragment from inside an AsyncTask . I
i'm using AsyncTask to retrive data from RSS ,,i'm showing a progress Dialog in

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.