I pass the thread to the Executorservice in the android
final ExecutorService downloadService= Executors.newSingleThreadExecutor(); Thread t = new Thread() { @Override public void run() { DriveContents contents = result.getDriveContents(); try { InputStream is = contents.getInputStream(); OutputStream os = new FileOutputStream(file1); byte[] buffer = new byte[1024]; int bytesRead; //read from is to buffer while((bytesRead = is.read(buffer)) !=-1){ os.write(buffer, 0, bytesRead); } is.close(); //flush OutputStream to write any buffered data to file os.flush(); os.close(); } catch (Exception e) { e.printStackTrace(); } downloadService.submit(t); but he gives an error
java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@298a067f rejected from java.util.concurrent.ThreadPoolExecutor@2f9a64c[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]