I have this class that gets called from a fragment. On progress update gets called but the message will not update. I also am not seeing any progress bar or spinner. Just the title and the message, seen some similar problems but nothing where the progress bar isn't showing at all. Also, my message will not update at all in onProgressUpdate but printing out the values does show that it increments inside of the onProgressUpdate.
Edit: Here is how I start the task
DownloadFilesTask download = new DownloadFilesTask();
download.execute(urls.toArray(new String[urls.size()]));
Here is the class
private class DownloadFilesTask extends AsyncTask<String, Integer, Long> {
ProgressDialog progressDialog;
@Override
protected void onPreExecute()
{
progressDialog = ProgressDialog.show(getActivity(), "Downloading","Downloaded 0/"+urls.size(), false);
progressDialog.setProgress(0);
progressDialog.setMax(urls.size());
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
}
@Override
protected Long doInBackground(String[] urls) {
int count = urls.length;
long totalSize = 0;
for (int i = 0; i < count; i++) {
//Do things in background here
publishProgress(new Integer[] {i});
}
return totalSize;
}
@Override
protected void onProgressUpdate(final Integer... progress) {
System.out.println(progress[0]); //This does print correctly
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
progressDialog.setProgress(progress[0]);
progressDialog.setMessage("Downloaded "+ progress[0] +"/"+urls.size());
}
});
}
@Override
protected void onPostExecute(Long result) {
progressDialog.dismiss();
Toast t = Toast.makeText(getActivity(), "Downloaded", Toast.LENGTH_LONG);
t.show();
}
}