diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java index bddd61f9..688010dc 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -347,7 +347,7 @@ import org.xml.sax.SAXException; if (TextUtils.isEmpty(key)) { throw new IllegalArgumentException("未知类型"); } - key += isDownload ? DOWNLOAD : UPLOAD; + key += (isDownload ? DOWNLOAD : UPLOAD) + obj.hashCode(); return key; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java index 83f82b28..35a030d1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java @@ -54,12 +54,12 @@ abstract class AbsSchedulers listener = mObservers.get(targetName); + AbsSchedulerListener listener = mObservers.get(getKey(obj)); if (listener == null) { listener = createListener(targetName); if (listener != null) { listener.setListener(obj); - mObservers.put(targetName, listener); + mObservers.put(getKey(obj), listener); } else { ALog.e(TAG, "注册错误,没有【" + targetName + "】观察者"); } @@ -73,12 +73,16 @@ abstract class AbsSchedulers>> iter = mObservers.entrySet().iterator(); iter.hasNext(); ) { Map.Entry> entry = iter.next(); - if (entry.getKey().equals(obj.getClass().getName())) { + if (entry.getKey().equals(getKey(obj))) { iter.remove(); } } } + private String getKey(Object obj) { + return obj.getClass().getName() + obj.hashCode(); + } + /** * 创建代理类 * 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 fd2d1acb..58a781ce 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -16,6 +16,7 @@ package com.arialyy.simple.download; +import android.content.Intent; import android.os.Bundle; import android.os.Environment; import android.util.Log; @@ -67,7 +68,7 @@ public class SingleTaskActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Aria.upload(this).register(); + Aria.download(this).register(); } /** @@ -207,7 +208,8 @@ public class SingleTaskActivity extends BaseActivity { startD(); break; case R.id.stop: - Aria.download(this).load(DOWNLOAD_URL).stop(); + //Aria.download(this).load(DOWNLOAD_URL).stop(); + startActivity(new Intent(this, SingleTaskActivity.class)); //Aria.download(this).load(DOWNLOAD_URL).removeRecord(); break; case R.id.cancel: @@ -243,6 +245,6 @@ public class SingleTaskActivity extends BaseActivity { @Override protected void onStop() { super.onStop(); - Aria.download(this).unRegister(); + //Aria.download(this).unRegister(); } } \ No newline at end of file