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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:49:49+00:00 2026-05-20T14:49:49+00:00

I have an AsyncTask that shows a progressDialog whilst working (it calls runOnUiThread from

  • 0

I have an AsyncTask that shows a progressDialog whilst working (it calls runOnUiThread from within doInBackground to show the progress dialog).

Whilst its running I want to allow the use of the back button to cancel the operation; someone else has had this problem: BACK Button is not working ,while progressDialog is running

For what ever reason I can’t reply to that thread, hence having to start another?! (Another question for another day)

I had the same idea as Sandy but this code is never called whilst the progressDialog is showing, why is this? I have implemented it inside my main activity class, does the progressDialog take the foreground focus away from my class temporarily?

  • 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-20T14:49:50+00:00Added an answer on May 20, 2026 at 2:49 pm

    First, you should show your dialog from OnPreExecute, hide it in OnPostExecute, and – if necessary – modify it by publishing progress. (see here)

    Now to your question: ProgressDialog.show() can take a OnCancelListener as an argument. You should provide one that calls cancel() on the progress dialog instance.

    example:

        @Override
        protected void onPreExecute(){
            _progressDialog = ProgressDialog.show(
                    YourActivity.this,
                    "Title",
                    "Message",
                    true,
                    true,
                    new DialogInterface.OnCancelListener(){
                        @Override
                        public void onCancel(DialogInterface dialog) {
                            YourTask.this.cancel(true);
                            finish();
                        }
                    }
            );
        }
    

    where _progressDialog is a ProgressDialog member of YourTask.

    This class was deprecated in API level 26. ProgressDialog is a modal
    dialog, which prevents the user from interacting with the app. Instead
    of using this class, you should use a progress indicator like
    ProgressBar, which can be embedded in your app’s UI. Alternatively,
    you can use a notification to inform the user of the task’s progress. LINK

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

Sidebar

Related Questions

I have a class that extends AsyncTask. In the doInBackground() method, I connect to
I have an AsyncTask that get info from the web. Sometimes the connection fails
I have a method that is executed using asyncTask with a progressdialog. After this
I have code that starts a ProgressDialog inside an AsyncTask , it looks like
My goal is to have an AsyncTask that can execute multiple times (one task
I have an Activity class which has an attribute that references an AsyncTask instance
I am trying to create downloading progress. I have my class which extends AsyncTask:
I am currently having trouble getting a value from an AsyncTask that gets data
I have a listview that contains values from webservice.Each page contains only 10 listitems
I have an inner class that downloads some images from the server. The problem

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.