From 815d549c3bbb568484ff32eee3c30a2934eced8d Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Wed, 7 Dec 2016 22:41:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dfragment=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/arialyy/aria/core/AriaManager.java | 31 ++++++++++++------- gradle.properties | 21 +++++++------ 2 files changed, 30 insertions(+), 22 deletions(-) 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 346b0ab1..d0553f81 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -7,6 +7,7 @@ import android.app.Service; import android.content.Context; import android.os.Build; import android.os.Bundle; +import android.support.v4.app.Fragment; import com.arialyy.aria.core.command.CmdFactory; import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.core.command.IDownloadCmd; @@ -21,11 +22,11 @@ import java.util.Set; * Aria管理器,任务操作在这里执行 */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public class AriaManager { - private static final Object LOCK = new Object(); - private static volatile AriaManager INSTANCE = null; - private Map mTargets = new HashMap<>(); + private static final Object LOCK = new Object(); + private static volatile AriaManager INSTANCE = null; + private Map mTargets = new HashMap<>(); private DownloadManager mManager; - private LifeCallback mLifeCallback; + private LifeCallback mLifeCallback; private AriaManager(Context context) { regAppLifeCallback(context); @@ -48,8 +49,8 @@ import java.util.Set; /** * 设置同时下载的任务数 */ - public void setDownloadNum(int num){ - if (num <= 0){ + public void setDownloadNum(int num) { + if (num <= 0) { throw new IllegalArgumentException("下载任务数不能小于1"); } mManager.getTaskQueue().setDownloadNum(num); @@ -60,7 +61,7 @@ import java.util.Set; */ public void stopAllTask() { List allEntity = mManager.getAllDownloadEntity(); - List stopCmds = new ArrayList<>(); + List stopCmds = new ArrayList<>(); for (DownloadEntity entity : allEntity) { if (entity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) { stopCmds.add(CommonUtil.createCmd(entity, CmdFactory.TASK_STOP)); @@ -73,8 +74,8 @@ import java.util.Set; * 删除所有任务 */ public void cancelAllTask() { - List allEntity = mManager.getAllDownloadEntity(); - List cancelCmds = new ArrayList<>(); + List allEntity = mManager.getAllDownloadEntity(); + List cancelCmds = new ArrayList<>(); for (DownloadEntity entity : allEntity) { cancelCmds.add(CommonUtil.createCmd(entity, CmdFactory.TASK_CANCEL)); } @@ -88,11 +89,16 @@ import java.util.Set; } private AMReceiver putTarget(Object obj) { - String clsName = obj.getClass().getName(); - AMReceiver target = mTargets.get(clsName); + String clsName = obj.getClass().getName(); + AMReceiver target = mTargets.get(clsName); if (target == null) { target = new AMReceiver(); target.obj = obj; + if (obj instanceof android.support.v4.app.Fragment) { + clsName += "_" + ((Fragment) obj).getActivity().getClass().getName(); + } else if (obj instanceof android.app.Fragment) { + clsName += "_" + ((android.app.Fragment) obj).getActivity().getClass().getName(); + } mTargets.put(clsName, target); } return target; @@ -149,7 +155,8 @@ import java.util.Set; @Override public void onActivityDestroyed(Activity activity) { Set keys = mTargets.keySet(); for (String key : keys) { - if (key.equals(activity.getClass().getName())) { + String clsName = activity.getClass().getName(); + if (key.equals(clsName) || key.contains(clsName)) { AMReceiver target = mTargets.get(key); if (target.obj != null) { if (target.obj instanceof Application || target.obj instanceof Service) break; diff --git a/gradle.properties b/gradle.properties index 1d3591c8..fed5c85c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,18 +1,19 @@ -# Project-wide Gradle settings. - -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. - +## Project-wide Gradle settings. +# # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html - +# # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -# Default value: -Xmx10248m -XX:MaxPermSize=256m +# Default value: -Xmx1024m -XX:MaxPermSize=256m # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - +# # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true \ No newline at end of file +# org.gradle.parallel=true +#Wed Dec 07 20:19:22 CST 2016 +systemProp.http.proxyPassword=7RbgsDfOoBn +systemProp.http.proxyHost=hilton.h.xduotai.com +systemProp.http.proxyUser=duotai +systemProp.http.proxyPort=10969