The progress dialog will not be displayed using the async task

I have been looking for an answer for this for some time. I have an async task that loads the database needed for my application, while this loading my application cannot do anything, since all the data it refers to is in this file, I have an application waiting file download, but I'm trying to show a progress dialog so that the user knows that something is happening while they wait for it to happen.

my code is currently

public class fileDownloader extends AsyncTask<Void, Integer, SQLiteDatabase> { private File dbFile; private ProgressDialog progressDialog; private Context context; private SQLiteDatabase database; private SQLiteDatabase.CursorFactory factory; public fileDownloader(Context c) { super(); context = c; } @Override protected void onPreExecute() { super.onPreExecute(); progressDialog = new ProgressDialog(this.context); progressDialog.setMessage("Downloading Database..."); progressDialog.setCancelable(false); progressDialog.setIndeterminate(true); progressDialog.show(); } @Override protected SQLiteDatabase doInBackground(Void... v) { .... } @Override protected void onPostExecute(SQLiteDatabase db1) { progressDialog.dismiss(); } 

however nothing appears, I also tried to directly call ProgressDialog.show in pre execute and move it to the calling activity without any luck.

Please, help!

+2
android android-asynctask progress-bar
source share
3 answers

the solution to this was to look at the calling class, which the UI thread was blocking, so the dialog never appeared.

+1
source share

Hmm - how long does your doInBackground method doInBackground ? Perhaps your dialogue is shown, but the time is too fast for the dialogue to display ...

0
source share

Below code works fine, I use it:

 private class DownloadHomeSectionData extends AsyncTask<Void, Void, Boolean> { ProgressDialog progressDialog; @Override protected void onPreExecute() { super.onPreExecute(); progressDialog = new ProgressDialog(mainScreen); progressDialog.setMessage(getResources() .getString(R.string.loading)); progressDialog.setCancelable(false); progressDialog.setIndeterminate(true); progressDialog.show(); } @Override protected Boolean doInBackground(Void... params) { for (HomeButton homeBtn : appDesigner.getHomeButtons()) { StorageManager.getInstance().downloadFileSyncronously( homeBtn.getTab_logo_selected_image()); StorageManager.getInstance().downloadFileSyncronously( homeBtn.getTab_logo_unselected_image()); } return null; } @Override protected void onPostExecute(Boolean result) { super.onPostExecute(result); progressDialog.dismiss(); } } 

In your case, I think you can pass the wrong context to the ProgressDialog .

0
source share

All Articles