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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:25:16+00:00 2026-06-04T09:25:16+00:00

How can i use AsyncTask Class to showing dialog when execute a task??? class

  • 0

How can i use AsyncTask Class to showing dialog when execute a task???

class TestAsynTask extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        ProgressDialog.show(???, null, null);
        super.onPreExecute();
    }
    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub
        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-04T09:25:16+00:00Added an answer on June 4, 2026 at 9:25 am

    Assuming that TestAsyncTask is an inner class to an Activity, then you can use the activity name .this to get the context. If TestAsyncTask is not an inner class, then you will want to pass an instance of your Activity into the constructor so that you can provide it as the Context to the ProgressDialog.show() method.

    Here is an example of the inner class method:

    class MyActivity extends Activity {
        //Activity Lifecycle methods
    
        class TestAsynTask extends AsyncTask<Void, Void, Void> {
            ProgressDialog dialog;
    
            @Override
            protected void onPreExecute() {
                dialog = ProgressDialog.show(MyActivity.this, "title", "message");
                super.onPreExecute();
            }
    
            @Override
            protected Void doInBackground(Void... params) {
                //very long computation...
                return null;
            }
    
            @Override
            protected void onPostExecute(Void void) {
               dialog.cancel();
            }
        }
    }
    

    You will notice that you should save off the ProgressDialog to a instance variable in the onPreExecute() method and call cancel() on it in the onPostExecute() method.

    The other approach looks similar:

    class MyActivity extends Activity {
        //Activity Lifecycle methods
    
    
    }
    
    class TestAsynTask extends AsyncTask<Void, Void, Void> {
        ProgressDialog dialog;
        MyActivity activity;        
    
        TaskAsynTask(MyActivity activity) {
            this.activity = activity;
        }
    
        @Override
        protected void onPreExecute() {
            dialog = ProgressDialog.show(activity, "title", "message");
            super.onPreExecute();
        }
    
        @Override
        protected Void doInBackground(Void... params) {
            //very long computation...
            return null;
        }
    
        @Override
        protected void onPostExecute(Void void) {
            dialog.cancel();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my AsyncTask class: private class Task extends AsyncTask<Void, Integer, Void> { @Override
Can I use getCacheDir() only in a class that extends Activity? I would like
In my Activity I use a class which extends from AsyncTask and a parameter
i am trying to use Alert Dialog Box and Async Task in the activity
class GoogleMusicAdapter extends TestFragmentAdapter implements TitleProvider { public GoogleMusicAdapter(FragmentManager fm) { super(fm); } @Override
I wanted to use AsyncTask to load images to the ListView. private class LoadImageTask
I'm trying to use an AsyncTask-extended class to handle connecting to a URL, parsing
I have a backgorund thread that extends AsyncTask and which I use in activity
I'm loading a bitmap in the background using the AsyncTask class. I use the
First, I have a class that extends AsyncTask. Then in the doInBackground() method, I

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.