Working with Android I’ve got an error while I try to show a progressbar in an asynctask. I have the error at the bold line. The variable context is the context of the app, I’m sure. Here there’s the code:
public class UpdateDBTask extends AsyncTask {
ProgressDialog progressDialogListFiles;
ProgressDialog progressDialogUpdateDB;
protected void onPreExecute () {
progressDialogUpdateDB = new ProgressDialog(context);
progressDialogUpdateDB.setIndeterminate(false);
progressDialogUpdateDB.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialogUpdateDB.setMessage("Analyzing files...");
progressDialogUpdateDB.setCancelable(false);
progressDialogUpdateDB.setProgress(0);
progressDialogListFiles = new ProgressDialog(context);
progressDialogListFiles.setIndeterminate(true);
progressDialogListFiles.setMessage("Listing files...");
progressDialogUpdateDB.setCancelable(false);
}
protected Boolean doInBackground(String... paths) {
updateDB(paths);
return true;
}
protected void updateDB(String[] paths) {
/*.....*/
**progressDialogListFiles.show();**
/*...*/
}
}
Can you help me? Thanks!
You are attempting to update the UI from a non-UI thread, namely the thread being used to process
doInBackground(). Please update your UI fromonPreExecute(),onProgressUpdate(), oronPostExecute().