处理一些内存泄漏问题

This commit is contained in:
张玉久
2020-06-24 15:33:53 +08:00
parent f3d01335a4
commit c7126e9836
2 changed files with 22 additions and 22 deletions

View File

@ -97,7 +97,7 @@ public class ShareUtils {
private String[] arrLabel = {"微信好友", "朋友圈", "QQ好友", "QQ空间", "新浪微博", "短信", "复制链接", "取消"};
private PopupWindow popupWindow;
private WeakReference<PopupWindow> popupWindow;
private ShareType mShareType;
public static ShareType shareType;//全局保存shareType分享成功后判断分享的类型
@ -125,10 +125,10 @@ public class ShareUtils {
};
private ShareUtils(Context context) {
mTencent = Tencent.createInstance(Config.TENCENT_APPID, context); //初始化QQ分享
mIWXAPI = WXAPIFactory.createWXAPI(context, Config.WECHAT_APPID); //初始化微信分享
WbSdk.install(context, new AuthInfo(context, Config.WEIBO_APPKEY, "http://www.sina.com", WEIBO_SCOPE));
mContext = context.getApplicationContext();
mTencent = Tencent.createInstance(Config.TENCENT_APPID, mContext); //初始化QQ分享
mIWXAPI = WXAPIFactory.createWXAPI(mContext, Config.WECHAT_APPID); //初始化微信分享
WbSdk.install(mContext, new AuthInfo(mContext, Config.WEIBO_APPKEY, "http://www.sina.com", WEIBO_SCOPE));
}
public static ShareUtils getInstance(Context context) {
@ -163,7 +163,7 @@ public class ShareUtils {
this.mShareType = shareType;
ShareUtils.shareType = mShareType;
View contentView = View.inflate(activity, R.layout.share_popup_layout, null);
View contentView = View.inflate(mActivity.get(), R.layout.share_popup_layout, null);
contentView.setFocusable(true);
contentView.setFocusableInTouchMode(true);
RecyclerView shareRecyclerView = contentView.findViewById(R.id.share_rv);
@ -206,33 +206,33 @@ public class ShareUtils {
arrLogo[7] = R.drawable.share_cancel_logo;
}
popupWindow = new SharePopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.MATCH_PARENT, true);
popupWindow.setAnimationStyle(R.style.popwindow_exit_only_anim_style);
popupWindow = new WeakReference<>(new SharePopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.MATCH_PARENT, true));
popupWindow.get().setAnimationStyle(R.style.popwindow_exit_only_anim_style);
//解决PopupWindow无法覆盖状态栏
popupWindow.setClippingEnabled(false);
popupWindow.get().setClippingEnabled(false);
int bottomLocation = -DisplayUtils.retrieveNavigationHeight(activity);
if (!DisplayUtils.isNavigationBarShow(activity)) {
bottomLocation = 0;
}
try {
popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, 0, bottomLocation);
popupWindow.get().showAtLocation(view, Gravity.NO_GRAVITY, 0, bottomLocation);
} catch (Exception e) {
e.printStackTrace();
}
contentView.setOnClickListener(v -> popupWindow.dismiss());
contentView.setOnClickListener(v -> popupWindow.get().dismiss());
contentView.setOnKeyListener((v, keyCode, event) -> {
if (keyCode == KeyEvent.KEYCODE_BACK
&& event.getRepeatCount() == 0
&& popupWindow != null
&& popupWindow.isShowing()) {
&& popupWindow.get().isShowing()) {
if (callBack != null) {
callBack.onCancel();
}
popupWindow.dismiss();
popupWindow.get().dismiss();
}
return false;
});
@ -272,7 +272,7 @@ public class ShareUtils {
}
if (mShareType != ShareType.shareGh) {
popupWindow.dismiss();
popupWindow.get().dismiss();
}
}
@ -311,7 +311,7 @@ public class ShareUtils {
loadBitMap(shareIcon, msg, req);
if (mShareType != ShareType.shareGh) {
popupWindow.dismiss();
popupWindow.get().dismiss();
}
}
@ -426,7 +426,7 @@ public class ShareUtils {
}
if (mShareType != ShareType.shareGh) {
popupWindow.dismiss();
popupWindow.get().dismiss();
}
}
@ -470,7 +470,7 @@ public class ShareUtils {
loadBitMap(shareIcon, msg, req);
if (mShareType != ShareType.shareGh) {
popupWindow.dismiss();
popupWindow.get().dismiss();
}
}
@ -491,7 +491,7 @@ public class ShareUtils {
if (mShareType != ShareType.shareGh) {
popupWindow.dismiss();
popupWindow.get().dismiss();
}
}
@ -532,7 +532,7 @@ public class ShareUtils {
}
if (mShareType != ShareType.shareGh) {
popupWindow.dismiss();
popupWindow.get().dismiss();
}
}
@ -542,7 +542,7 @@ public class ShareUtils {
cmb.setText(copyContent);
if (mShareType != ShareType.shareGh) {
Utils.toast(mContext, "复制成功");
popupWindow.dismiss();
popupWindow.get().dismiss();
} else {
Utils.toast(mContext, "复制成功,请到微信/QQ粘贴分享");
}
@ -618,7 +618,7 @@ public class ShareUtils {
break;
case 7:
if (mShareType != ShareType.shareGh) {
popupWindow.dismiss();
popupWindow.get().dismiss();
} else {
copyLink("推荐光环助手,绿色安全的手游加速助手:" + shareUrl);
}