0

I need advice about ProgressDialog , I show dialog like

            pd = ProgressDialog.show(
                    Dashboard.this,
                    "LOADING...",
                    "PLEASE WAIT", true, false);

and it shows, but it when in background is intensive calculation that circle stops to spin ( like it is blocked). I am running this code above inside onClick button. What to change to avoid this blocking or that is impossible ?

Damir
  • 54,277
  • 94
  • 246
  • 365

2 Answers2

1

You have to move your intensive calculation to another Thread, to not block UI thread

see another SO question for example how to use AsyncTask and ProgressDialog together

progressDialog in AsyncTask

Community
  • 1
  • 1
Marek Sebera
  • 39,650
  • 37
  • 158
  • 244
1

When you say your progress dialog does not spin, it actually means that your intensive calculation is blocking the main /UI thread

you should make use of an Asynctask

Also get a hang of painless threading in android

It will run in the background without causing hiccups in the UI thread...

Since android apps run on a single main (UI ) thread, you should avoid doing heavy tasks on the UI thread

An asynctask is basically an intelligent worker thread provided by the android system.. It contains helper methods wherein you can easily decide what you want to do

A progress dialog should be created in onPreExecute() and dismissed in onPostExecute()

Do intensive task in doInBackgound()

Here are some tutorials:

easy to understand asynctask

Pratik Bhat
  • 7,166
  • 2
  • 35
  • 57