Android-Download-Manager-Pro icon indicating copy to clipboard operation
Android-Download-Manager-Pro copied to clipboard

AsyncWorker pause failed.

Open easternHong opened this issue 8 years ago • 1 comments

//check whether a thread is interruptted or not by this is not a good choice.
Thread#isInterrupted()

i invoke downloader.puaseDownload(int token); and it finally interrupts the AsyncWorker,but in AsyncWorker this.isInterrupted() is false. so observer.rebuild(chunk); is invoked .

that is to say ,invoke downloader.puaseDownload(int token); and observer.rebuild(chunk);will be invoked too. so, the task's state is wrong.

//my solution

volatile boolean interrupt = false;

@Override
public void interrupt() {
      super.interrupt();
      interrupt = true;
}

//update #run
```java
 while (!interrupt &&
       (len = remoteFileIn.read(buffer)) > 0) {
       watchDog.reset();
       chunkFile.write(buffer, 0, len);
       process(len);
 }
if (!interrupt) {
     observer.rebuild(chunk);
}

easternHong avatar May 10 '16 07:05 easternHong

it is work for me, thanks.

BruceYang-yeu avatar Jun 25 '16 00:06 BruceYang-yeu