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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:30:32+00:00 2026-05-28T02:30:32+00:00

I am trying to have a ProgressDialog appear when I am getting some data,

  • 0

I am trying to have a ProgressDialog appear when I am getting some data, in Activity.
The activity runs normally, and the data are obtained, but the ProgressDialog does not appear.

 private void updateData() {
        ProgressDialog dialog = ProgressDialog.show(ParkActivity.this, "fvhnn", "A actualizar. Aguarde por favor...", true);
        ...
        ...
        dialog.dismiss();
        ...
 }

follow the code of my Activity.

public class ParkActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set View to register.xml
        setContentView(R.layout.park);

        SharedPreferences settings = getSharedPreferences(PREF_FILE, 0);
        int ocupados = settings.getInt("ocupados", -1);

        if(ocupados == -1) {
            ((TextView) findViewById(R.id.txtPercentageOcupation)).setVisibility(View.INVISIBLE);
            ((TextView) findViewById(R.id.txtLastUpdate)).setVisibility(View.INVISIBLE);
            ((TextView) findViewById(R.id.txtPlacesAvailable)).setVisibility(View.INVISIBLE);
            ((Button) findViewById(R.id.btnParkUpdate)).setVisibility(View.INVISIBLE);

            updateData();
        } else {
            int total = settings.getInt("total", 440);
            long data = settings.getLong("data", 0);

            putData(ocupados, total, data);
        }


        Button btnUpdate = (Button) findViewById(R.id.btnParkUpdate);
        btnUpdate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                updateData();
            }
        });
    }

    private void updateData() {
        ProgressDialog dialog = ProgressDialog.show(ParkActivity.this, "fvhnn", "A actualizar. Aguarde por favor...", true);
        SharedPreferences settings = getSharedPreferences(PREF_FILE, 0);
        String session = settings.getString("sessionID", "null");
        int[] vagas = ISEP_Proxy.vagas(session);
        Date dt = new Date();
        putData(vagas[0], vagas[1], dt.getTime());
        dialog.dismiss();

        // save data
        SharedPreferences.Editor editor = settings.edit();
        editor.putInt("ocupados", vagas[0]);
        editor.putInt("total", vagas[1]);
        editor.putLong("data", dt.getTime());

        editor.commit();
    }

    private void putData(int ocupados, int total, long date) {
        String placesFormat = getResources().getString(R.string.PLACES_AVAILABLE);
        String percentageFormat = getResources().getString(R.string.PERCENTAGE_OCUPATION);
        String lastUpdate = getResources().getString(R.string.LAST_UPDATE);
        double percentage =  100.0 * ocupados / total;

        SimpleDateFormat df = new SimpleDateFormat("HH'h'mm 'de' dd-MM-yyyy");

        ((TextView) findViewById(R.id.txtPercentageOcupation)).setVisibility(View.VISIBLE);
        ((TextView) findViewById(R.id.txtLastUpdate)).setVisibility(View.VISIBLE);
        ((TextView) findViewById(R.id.txtPlacesAvailable)).setVisibility(View.VISIBLE);
        ((Button) findViewById(R.id.btnParkUpdate)).setVisibility(View.VISIBLE);

        ((TextView) findViewById(R.id.txtPercentageOcupation)).setText(String.format(percentageFormat, ((int) percentage) + "%"));
        ((TextView) findViewById(R.id.txtPlacesAvailable)).setText(String.format(placesFormat, total - ocupados));
        ((TextView) findViewById(R.id.txtLastUpdate)).setText(String.format(lastUpdate, df.format(date)));
    }
}

Anyone know what the problem is?


EDIT

@Ted Hopp Suggest to use a AsyncTask.
I created the class GetISEPData and placed inside the dialog, but now the app gives me an error and closes.

private class GetISEPData extends AsyncTask<Void, Void, Void> {
    Context cx;
    ProgressDialog dialog;

    public GetISEPData (Context context) {
        cx = context;
    }

    @Override
    protected Void doInBackground(Void... params) {
        SharedPreferences settings = getSharedPreferences(PREF_FILE, 0);
        String session = settings.getString("sessionID", "null");
        int[] vagas = ISEP_Proxy.vagas(session);
        Date dt = new Date();
        putData(vagas[0], vagas[1], dt.getTime());

        // save data
        SharedPreferences.Editor editor = settings.edit();
        editor.putInt("ocupados", vagas[0]);
        editor.putInt("total", vagas[1]);
        editor.putLong("data", dt.getTime());

        editor.commit();            
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        dialog = ProgressDialog.show(ParkActivity.this, "", "A actualizar. Aguarde por favor...", true);
    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        dialog.dismiss();
    }       
}

for invoke put this:

    Button btnUpdate = (Button) findViewById(R.id.btnParkUpdate);
    btnUpdate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            new GetISEPData(ParkActivity.this).execute();
        }
    });
  • 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-28T02:30:33+00:00Added an answer on May 28, 2026 at 2:30 am

    In between the call to show() and the call to dismiss(), you need to do the work in a separate thread. Until you return control to the framework, the dialog doesn’t have a chance to get drawn. Take a look at AsyncTask for an easy way to do this.

    EDIT: In your updated version of your code, you have the logic for onPreExecute and onPostExecute reversed — you are trying to dismiss the dialog before it is shown!

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

Sidebar

Related Questions

I'm trying to make a simple ProgressDialog appear while my AsyncTask is fetching data.
I have trying to create this jquery dropdown, but it doesn't work, Does anybody
I'm trying to have a new layer appear above existing content on my site
I have a ProgressDialog running in a AsyncTask. I`m trying to achive that as
I am trying to launch a new intent after I have loaded data. I
I have been trying to use a .gif file from my resources, but I
Okay I have been trying to get this to work for some time now.
I am trying to create an app that will send some data to a
Trying to have a page which will not take everything from layouts/application.html.erb, Is it
trying to have some sort of gradiented border by having a parent element have

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.