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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:54:10+00:00 2026-06-15T02:54:10+00:00

My ProgressDialog works in the case that i show() in my oncreate method. public

  • 0

My ProgressDialog works in the case that i show() in my oncreate method.

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 
        pd = ProgressDialog.show(this, "Working", "Retreiving Neaby Restaurants", true, true);  // initializes the progress dialog
        pd.setCanceledOnTouchOutside(false);  // on newer versions of android touching outside of the screen will close the dialog. I decided to make it only cancelable when the back button is pressed.
        setContentView(R.layout.nearby_places_list);

However, the dialog code wont work if i use it in an async task because its not in the on create(). The arguements show(this, “Working”, “Retreiving Neaby Restaurants”, true, true) arnt allowed outside of the onCreate():

class MyAsync extends AsyncTask<Void, Integer, Boolean>{  // this task is for populating the listview

        @Override 
        protected void onPreExecute() {
            //ProgressDialog.show(context, "Working", "Retreiving Neaby Restaurants");
            pd = ProgressDialog.show(this, "Working", "Retreiving Neaby Restaurants", true, true);  // initializes the progress dialog
            pd.setCanceledOnTouchOutside(false);  // on newer versions of android touching outside of the screen will close the dialog. I decided to make it only cancelable when the back button is pressed.
        }

This is somewhat upsetting because i wanted to show the dialog at the start of an async task but not long before that task is called.

So my question is how do make this work inside of the async task on the onPreExecute() I don’t want to have to show() until the users actually start using the async task.

  • 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-15T02:54:12+00:00Added an answer on June 15, 2026 at 2:54 am

    use

    pd = ProgressDialog.show(yourActivitName.this, "Working", "Retreiving Neaby Restaurants", true, true);
    

    in onPreExecute()

    this is actually the Context of the activity. An important thing you need to use often in future.

    You can also make a Class level variable Context activityContext

    and initialize it after setContentView in onCreate like this

    activityContext=this

    and then you can also use

    pd = ProgressDialog.show(activityContext, "Working", "Retreiving Neaby Restaurants", true, true);

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

Sidebar

Related Questions

ProgressDialog onClick not working.. here is my code .. Basically i want to show
This code isn't working. The loading screen doesn't show, however if I take out
This is a gridview that get image from json. and it works fine. I
I'm having some problems displaying a ProgressDialog. I have a method that scrapes information
I am using this simple code public class Main extends Activity { private ProgressDialog
I start studying this: Android SplashScreen and my app works perfectly with this method.
I'm beginning to think that to get a ProgressDialog to work the AsyncTask has
My program uses wx.ProgressDialog to give feedback on a process that is in multiple
I've developed a simple asynctask with progressdialog attached to it, to show progress of
I've created a ProgressDialog to show when the user click on a button. My

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.