anonymous implementation of android.content.DialogInterface$OnDismissListener
内侧泄漏信息
In com.eebbk.askhomework.content:1.10.0.0:1100000.
bfc-leakcanary:5.0.12-bugfix.
- com.eebbk.askhomework.content.view.SecondActivity has leaked:
- GC ROOT android.os.HandlerThread.
- references android.os.Message.obj
- references com.eebbk.askhomework.content.other.moduleother.function.middle.view.SyncMiddleFragment$1.this 0 ( a n o n y m o u s i m p l e m e n t a t i o n o f a n d r o i d . c o n t e n t . D i a l o g I n t e r f a c e 0 (anonymous implementation of android.content.DialogInterface 0(anonymousimplementationofandroid.content.DialogInterfaceOnDismissListener)
- references com.eebbk.askhomework.content.other.moduleother.function.middle.view.SyncMiddleFragment.mBgGroupView
- references androidx.constraintlayout.widget.ConstraintLayout.mContext
- leaks com.eebbk.askhomework.content.view.SecondActivity instance
解决方法使用静态内部了+弱引用
public static class WeakDialogListener implements DialogInterface.OnDismissListener {
private WeakReference<SyncMiddleFragment> mWeakReference ;
public WeakDialogListener(SyncMiddleFragment fragment) {
this.mWeakReference = new WeakReference<>(fragment);
}
@Override
public void onDismiss(DialogInterface dialog) {
if (!WeakRefUtil.isWeakRefAvailable(mWeakReference)) {
return;
}
SyncMiddleFragment fragment = mWeakReference.get();
if (fragment != null && fragment.mSubjectText != null) {
fragment.mSubjectText.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.mipmap.grade_down_arraw, 0);
}
}
}
使用方法:
private WeakDialogListener mWeakDialogListener = new WeakDialogListener(this);
mCatalogDialog = new MiddleCatalogDialog(mContext, mPresenter.getCatalogData());
mCatalogDialog.setOnDismissListener(mWeakDialogListener);