I’ve got a file download application which I need to update progress using Asnc Task method
The progress will be displayed by Dialog and Notification Bar simultaneously, just like the sample in the Google PLay
When I run the method , Notification Bar shows extremely slow response.
IN the ONProgressUpdate, I only update two UI progress without synchornization.
When I use thread sleep to slow down the process, it runs smoothly but the download speed is very low.
How can we ensure two UI threads running smoothly while maintaining acceptably fast downloading speed?
this is the Code
Please answer 🙂
@Override
protected void onProgressUpdate(Integer... values) {
if (values.length>0) {
//Log.d("Download Activity", "progressUpdate:"+values[0]);
if (values[0] < 0) {
this.cancel(true);
showNetworkErrorDialog();
} else {
//size += values[0];
//Log.d("Download Activity", "download size:"+size);
//downloadedGoodListSize += values[0];
//downloadProgressBar.incrementProgressBy(values[0]);
setCurrentProgress(values[0]);
downloadProgressBar.setProgress(values[0]);
double currentProg = downloadProgressBar.getProgress()*1.0/downloadProgressBar.getMax()*100;
//progressTextView.setText( decimalFormat.format(downloadedGoodListSize*1.0/downloadProgressBar.getMax()*100.0)+"%");
progressTextView.setText(decimalFormat.format(downloadProgressBar.getProgress()*1.0/downloadProgressBar.getMax()*100)+"%");
notification.contentView.setProgressBar(R.id.pb, 100, (int)currentProg, false);
nm.notify(notificationID, notification);
}
}
}
@Override
protected void onPostExecute(Boolean result) {
Log.i("Download Activity", "onPostExecute: starting");
downloadProgressBar.setProgress(downloadProgressBar.getMax());
progressTextView.setText(100+"%");
wheelProgressBar.setVisibility(View.GONE);
downloadingTextView.setText(getFinishedText());
notification.contentView.setProgressBar(R.id.pb, 100, 100, false);
nm.notify(notificationID, notification);
nm.cancelAll();
Log.i("Download Activity", "onPostExecute: set interface ok");
finishDialog.show();
}
The below is my code