From 04354a81d0891048e647e79be28c19c80009e747 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Fri, 9 Jun 2017 20:33:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=A0=E9=99=A4=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E4=B8=AD=E7=9A=84=E6=B8=B8=E6=88=8F=E8=BF=9E=E7=BB=AD?= =?UTF-8?q?=E4=B8=A4=E6=AC=A1=E8=B0=83=E7=94=A8onCancelTask=E5=9B=9E?= =?UTF-8?q?=E6=8E=89=E7=9A=84bug=20https://github.com/AriaLyy/Aria/issues/?= =?UTF-8?q?33?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aria/build.gradle | 4 ++-- .../arialyy/aria/core/download/DownloadTask.java | 16 +++++++++------- .../simple/download/SingleTaskActivity.java | 2 ++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Aria/build.gradle b/Aria/build.gradle index c0c5108c..af990516 100644 --- a/Aria/build.gradle +++ b/Aria/build.gradle @@ -23,8 +23,8 @@ dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' -// compile project(':AriaCompiler') - compile project(':AriaAnnotations') + compile project(':AriaCompiler') +// compile project(':AriaAnnotations') } //apply from: 'jcenter.gradle' diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java index 97bd7917..0ac71387 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java @@ -133,17 +133,19 @@ public class DownloadTask extends AbsTask { */ @Override public void cancel() { if (!mEntity.isDownloadComplete()) { + if (!mUtil.isDownloading()) { + if (mOutHandler != null) { + mOutHandler.obtainMessage(DownloadSchedulers.CANCEL, this).sendToTarget(); + } + //发送取消下载的广播 + Intent intent = CommonUtil.createIntent(mContext.getPackageName(), Aria.ACTION_CANCEL); + intent.putExtra(Aria.DOWNLOAD_ENTITY, mEntity); + mContext.sendBroadcast(intent); + } mUtil.cancelDownload(); mUtil.delConfigFile(); mUtil.delTempFile(); mEntity.deleteData(); - if (mOutHandler != null) { - mOutHandler.obtainMessage(DownloadSchedulers.CANCEL, this).sendToTarget(); - } - //发送取消下载的广播 - Intent intent = CommonUtil.createIntent(mContext.getPackageName(), Aria.ACTION_CANCEL); - intent.putExtra(Aria.DOWNLOAD_ENTITY, mEntity); - mContext.sendBroadcast(intent); } } diff --git a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java index 91fe5a3f..558cdf24 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -183,12 +183,14 @@ public class SingleTaskActivity extends BaseActivity { @Download.onTaskStop void taskStop(DownloadTask task) { if (task.getKey().equals(DOWNLOAD_URL)) { mUpdateHandler.sendEmptyMessage(DOWNLOAD_STOP); + L.d(TAG, "task__stop"); } } @Download.onTaskCancel void taskCancel(DownloadTask task) { if (task.getKey().equals(DOWNLOAD_URL)) { mUpdateHandler.sendEmptyMessage(DOWNLOAD_CANCEL); + L.d(TAG, "task__cancel"); } }