The mobile application provides the user with the ability to download email attachments from a remote site. Connecting to a remote server and downloading content is carried out in a separate stream. The dialog is displayed to the user using the cancel.Herewith command I am providing pseudocode.
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();
Now I am in the process of adding the cancel command to the dialog with the progress indicator. When the user clicks the “Cancel” button on the mobile phone, the modeless dialog can be deleted by calling the dispose () method. How can I abruptly stop the stream that receives email attachments through streaming? Please help me solve this problem.
source share