I have several actions in my application that hit the web service. Since I do not want to delay the main thread, this code is in AsyncTask. However, I donโt want the user to manipulate the Activity during the web service call, so before running AsyncTask, I show the ProgressDialog, which rotates and locks the screen. In the onPostExecute AsyncTask method, the first thing I do is reject the ProgressDialog.
This should prevent the user from manipulating the action without actually blocking the main thread.
However, I noticed several times when the ProgressDialog is never disabled and the user is stuck. AsyncTask has completed execution, onPostExcute has completed, but the ProgressDialog is still displayed. ProgressDialog has no chance of getting fired, and the user is stuck on the screen. Their only option is to visit the Android Settings app and force my application to terminate.
Does anyone know why this is happening? What can I do to fix this?
Relevant Code:
This is how I show the ProgressDialog and run the task:
mProgress = ProgressDialog.show(this, "", "Syncing...", true); (new MyAsyncTask()).execute(intUserId);
This is the onPostExcute task for the task. No "@Override"
protected void onPostExecute(Boolean result) { if (mProgress != null) { mProgress.dismiss(); mProgress = null; } }
source share