在项目中使用Handler时,会出现警告提示,也会在Problems中进行统计和显示,如下图:
把鼠标放在,就会提示This Handler class should be static or leaks might occur,如下:
@SuppressLint("HandlerLeak")
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
};
};
解决方法:
private Handler mHandler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
return false;
}
});
时间: 2024-10-12 10:13:21