|
|
@ -202,15 +202,15 @@ import java.util.Set; |
|
|
|
//如果Dialog已经设置Dismiss事件,则查找cancel事件
|
|
|
|
//如果Dialog已经设置Dismiss事件,则查找cancel事件
|
|
|
|
if (dismissMsg != null) { |
|
|
|
if (dismissMsg != null) { |
|
|
|
Field cancelField = CommonUtil.getField(dialog.getClass(), "mCancelMessage"); |
|
|
|
Field cancelField = CommonUtil.getField(dialog.getClass(), "mCancelMessage"); |
|
|
|
Message cancelMsg = (Message) dismissField.get(dialog); |
|
|
|
Message cancelMsg = (Message) cancelField.get(dialog); |
|
|
|
if (cancelMsg != null) { |
|
|
|
if (cancelMsg != null) { |
|
|
|
Log.e(TAG, "你已经对Dialog设置了Dismiss和cancel事件。为了防止内存泄露," |
|
|
|
Log.e(TAG, "你已经对Dialog设置了Dismiss和cancel事件。为了防止内存泄露," |
|
|
|
+ "请在dismiss方法中调用Aria.whit(this).removeSchedulerListener();来注销事件"); |
|
|
|
+ "请在dismiss方法中调用Aria.whit(this).removeSchedulerListener();来注销事件"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
dialog.setCancelMessage(createCancelMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
dialog.setCancelMessage(createDismissMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (IllegalAccessException e) { |
|
|
|
} catch (IllegalAccessException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
@ -236,6 +236,55 @@ import java.util.Set; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 创建Dialog取消消息 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private Message createCancelMessage() { |
|
|
|
|
|
|
|
final Message cancelMsg = new Message(); |
|
|
|
|
|
|
|
cancelMsg.what = 0x44; |
|
|
|
|
|
|
|
cancelMsg.obj = new Dialog.OnCancelListener() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public void onCancel(DialogInterface dialog) { |
|
|
|
|
|
|
|
destroySchedulerListener(dialog); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
return cancelMsg; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 创建Dialog dismiss取消消息 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private Message createDismissMessage() { |
|
|
|
|
|
|
|
final Message cancelMsg = new Message(); |
|
|
|
|
|
|
|
cancelMsg.what = 0x43; |
|
|
|
|
|
|
|
cancelMsg.obj = new Dialog.OnDismissListener() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public void onDismiss(DialogInterface dialog) { |
|
|
|
|
|
|
|
destroySchedulerListener(dialog); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
return cancelMsg; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* onDestroy |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void destroySchedulerListener(Object obj) { |
|
|
|
|
|
|
|
Set<String> keys = mTargets.keySet(); |
|
|
|
|
|
|
|
String clsName = obj.getClass().getName(); |
|
|
|
|
|
|
|
for (String key : keys) { |
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
target.removeSchedulerListener(); |
|
|
|
|
|
|
|
mTargets.remove(key); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Activity生命周期 |
|
|
|
* Activity生命周期 |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -266,19 +315,7 @@ import java.util.Set; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override public void onActivityDestroyed(Activity activity) { |
|
|
|
@Override public void onActivityDestroyed(Activity activity) { |
|
|
|
Set<String> keys = mTargets.keySet(); |
|
|
|
destroySchedulerListener(activity); |
|
|
|
for (String key : keys) { |
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
target.removeSchedulerListener(); |
|
|
|
|
|
|
|
mTargets.remove(key); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|