在项目中使用Handler时,会出现警告提示
,也会在Problems中进行统计和显示,如下图:
把鼠标放在,就会提示This Handler class should be static or leaks might occur,如下:
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;
}
});
};
解决方法: private Handler mHandler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
return false;
}
});
SimpleDateFormat
// getTimeInstance(), or use new SimpleDateFormat(String template, Locale
// locale) with for example Locale.US for ASCII dates.
@SuppressLint("SimpleDateFormat")
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
"yyyy-MM-ddHH:mm:ss");
解决方法:
"yyyy年MM月dd日HH时mm分", Locale.getDefault());
@SuppressLint("UseSparseArrays")
public static Map CMD_MAP = new HashMap();
boolean b = "String".toUpperCase().equals("STRING");
解决方法:
boolean b = "String".equalsIgnoreCase("STRING");
警告原因:Implicitly using the default locale is a common source of bugs: Use toUpperCase(Locale) instead
// To get local formatting use getDateInstance(), getDateTimeInstance(), or
// getTimeInstance(), or use new SimpleDateFormat(String template, Locale
// locale) with for example Locale.US for ASCII dates.
@SuppressLint("SimpleDateFormat")
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
"yyyy-MM-ddHH:mm:ss");
解决方法:
SimpleDateFormat newSimpleDateFormat = new SimpleDateFormat(
"yyyy年MM月dd日HH时mm分", Locale.getDefault());
new HashMap()
@SuppressLint("UseSparseArrays")
public static Map CMD_MAP = new HashMap();
警告原因:Use new SparseArray(...) instead for better performance
"String".toUpperCase(); "String".toLowerCase();
@SuppressLint("DefaultLocale")
boolean b = "String".toUpperCase().equals("STRING");
解决方法:
boolean b = "String".equalsIgnoreCase("STRING");
警告原因:Implicitly using the default locale is a common source of bugs: Use toUpperCase(Locale) instead