title: Android How to stop/kill/cancel Media Upload or Download
body: <p>I create a AsyncTask to Upload or Download files on my Google Drive.</p>
  
  <p>This is an example of a part of my code to upload a file:</p>
  
  <pre><code>public class AsyncUpload extends AsyncTask&lt;String, String, String&gt;{
  
      Context c;
  
  
  
      public AsyncUpload(Context c) {
          super();
          this.c = c;
      }
  
  
      @Override
      protected String doInBackground(String... params) {
  
  
  
          try{
  
              // File's binary content
              java.io.File fileContent = new java.io.File(localFilePath);
  
              InputStreamContent mediaContent = new InputStreamContent(FileInfo.getMime(localFilePath), new BufferedInputStream(new FileInputStream(fileContent)));
              mediaContent.setLength(fileContent.length());
  
  
              // File's metadata.
              File body = new File();
              body.setTitle(fileContent.getName());
              body.setMimeType(FileInfo.getMime(localFilePath));
  
              if(parentId!=null){
                  ParentReference parent = new ParentReference();
                  parent.setId(parentId);
                  body.setParents(Arrays.asList(parent)); 
              }
  
  
              Drive.Files.Insert request = drive.files().insert(body, mediaContent);
              MediaHttpUploader uploader = request.getMediaHttpUploader();
              uploader.setDirectUploadEnabled(false);
              uploader.setChunkSize(MediaHttpUploader.MINIMUM_CHUNK_SIZE); 
              uploader.setProgressListener(mediaHttpUploaderProgressListener);
              File file = request.execute();
              if (file != null) {
                  Log.i(TAG,"File Uploaded");
                  isAttempt=false;
                  return file;
              }
  
          } catch (IOException e) {
              Log.e(TAG,"IOEXCEPTION Message:\n"+e.getMessage());
          }
  
  
          return null;
      }
  
  }
  </code></pre>
  
  <p>This code works perfectly but I don't know how to stop it while a file is uploading (or downloading with a similar code)!</p>
  
  <p>Please help me!</p>
  
  <p>Many Thanks</p>