避免使用非静态的内部类,容易导致内存溢出
程序员文章站
2022-04-19 17:36:13
...
1.非静态内部类会隐式的持有外部类的引用
public static class MyHandler extends Handler{
private final WeakReference<Activity> mActivity = null;
public MyHandler(Activity mActivity){
mActivity = new WeakReference<Activity>(mActivity);
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(mActivity.get()!=null){
}
}
}