I’ve got an AsyncTask like this:
private class RetrieveDataAsyncTask extends AsyncTask<Void, Void, Boolean> {
ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(getSherlockActivity(), "In progress", "Loading");
}
@Override
protected Boolean doInBackground(Void... params) {
try {
currentScreen.retrieveData();
return true;
} catch (IOException ex) {
return false;
}
}
@Override
protected void onPostExecute(Boolean result) {
progressDialog.dismiss();
if (result) {
currentScreen.retrieveDataFinished();
} else {
showExceptionOccurred();
}
}
Now when the AsyncTask takes less than 500ms, I don’t want to show the ProgressDialog, it only causes flickering and can be irritating.
What I want is to wait 500ms, check if the AsyncTask is still busy, and if so, show the ProgressDialog.
How can I achieve that?
Try doing it like this: