Android-Download-Manager-Pro
Android-Download-Manager-Pro copied to clipboard
AsyncWorker pause failed.
//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);
}
it is work for me, thanks.