Skip to content Skip to sidebar Skip to footer

Progressdialog In Android Asynctask Does Not Display At The Right Time

So I've got these long running server calls over what is basically OData going on in my Android application. The consumer of the calls uses .execute().get() to wait for the respon

Solution 1:

Ok, your problem is your .get(). .get is a blocking call. This means you won't return to the event loop (the code in the Android Framework that calls onCreate, onPause, event handlers, onPostExecute, onPreExecute, etc) until after it returns. If you don't return to the event loop, you won't ever go into the drawing code, and you won't display the progress dialog. If you want to show the dialog, you need to rearchitect your app to actually use the task asynchronously. Side note- if you're calling .get() like that on your UI thread, your entire app will freeze up and look broken. That's why they forced people to not do network IO on the UI thread in the first place.

Solution 2:

As @Gabe-Sechan says, the .get() is the reason why your UI freezes and your ProgressDialog doesn't show as you want. On the other hand, I disagree with him when he says:

If you want to show the dialog, you need to rearchitect your app to actually use the task asynchronously.

If you simply remove your .get() and leave you dialog showing in the onPreExecute() and dismissing in the onPostExecute(String result), you'll get what you are looking for: a ProgressDialog shown while the task is executed.

UPDATE:

I started a question based on the sense/usefulness of using the get() method of Android's AsyncTask class.

Post a Comment for "Progressdialog In Android Asynctask Does Not Display At The Right Time"