移動應用程序向用戶提供從遠程下載電子郵件附件的選項。與遠程服務器連接並下載內容在單獨的線程中執行。向用戶顯示取消命令。赫瑞史密斯我提供了僞代碼。當用戶觸發取消命令時停止線程
new Thread(new Runnable()
public void run(){
try{
//open connection to remote server
//get data input stream
//create byte array of length attachment size
//show modeless dialog with the message "Downloading..."
for(int i=0;i<attachmentSize;i++){
//set the progress indicator of the modeless dialog based upon for iteration
//read the byte from input stream and store it in byte array
}
//open file connection outputstream and store the downloaded content as a file in mobile file system
//show dialog with the message "attachment successfully downloaded"
}
catch(IOException ioe) { }
catch(Exception ex) { }
}
).start();
現在我正在向具有進度指示器的對話框添加取消命令。當用戶點擊手機中的「取消」命令時,可通過調用dispose()方法來處理非模態對話框。我如何突然停止通過流式傳輸獲取電子郵件附件的線程? 請幫我解決這個問題。