timer = new Timer();
boolean isOnline = WebServiceHandler.isOnline(this);
if (isOnline) {
startDownloadTask();
task = new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
int progress = downloadProgressBar.getProgress();
notification.contentView.setProgressBar(R.id.pb, downloadProgressBar.getMax(), progress, false);
nm.notify(notificationID, notification);
}
};
timer.schedule(task, 10, 500);
} else {
connectionErrorDialog.show();
onDestroy();
}
}
@Override
public void stopDownloadTask() {
downloadGoodListTask.cancel(true);
downloadGoodListTask.setActivityIsRunning(false);
downloadGoodListTask = null;
}
protected void onDestroy() {
super.onDestroy();
Log.i("Download Activity", "starting to destroy");
//timer.cancel();
wheelProgressBar.destroyDrawingCache();
downloadProgressBar.destroyDrawingCache();
finishDialog.dismiss();
connectionErrorDialog.dismiss();
downloadProgressBar = null;
wheelProgressBar = null;
progressTextView = null;
downloadingTextView = null;
finishDialog = null;
connectionErrorDialog = null;
//timer = null;
nm.cancel(notificationID);
nm = null;
notification = null;
/*downloadTask.cancel(true);
downloadTask.activityIsRunning = false;
downloadTask = null;*/
stopDownloadTask();
timer.cancel();
System.gc();
Log.i("Download Activity", "destroyed");
}
@Override
public void stopDownloadTask() {
downloadGoodListTask.cancel(true);
downloadGoodListTask.setActivityIsRunning(false);
downloadGoodListTask = null;
}
答案 0 :(得分:2)
不要从UI线程外部访问Android UI工具包。使用runOnUIThread方法,向Handler发送消息或使用AsyncTask。
答案 1 :(得分:0)
异常是因为,downloadGoodListTask为null。或者,您应该初始化为某个值或在stopDownloadTask()中处理异常。