선생님, 인터넷에 연결되어 있지 않으면 메시지를 처리하려고합니다. 그러나 네트워크 연결이있는 경우 계속 다운로드를 진행하면 null 예외 오류가 발생합니다. 처음에는 네트워크 연결에 오류 메시지가 표시되지만 예를 누르면 예외 오류 메시지가 나타납니다. 이 사건을 처리 할 때 우리는 무엇을 더 처리해야합니까?비동기 작업 다운로드 연결이없는 경우 Null 포인터 예외가 발생합니다.
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;
}
당신은 알림 바가 게시 실행시 처리되어야한다는 것을 의미합니까? –
onProgressUpdate를 사용하십시오. 여기에 예제가 있습니다. https://eliasbland.wordpress.com/2011/03/11/an-example-of-how-to-run-a-background-task-and-report-progress-in-the-status- bar-using-asynctask-on-android / –