java - What is the SuppressLint Java annotation?
问题描述
I am trying to understand the purpose of the @SuppressLint
Java annotation in the following code:
@SuppressLint("StaticFieldLeak")
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new
ProgressDialog(MyActivity.this);
mProgressDialog.setTitle("Loading Profile");
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}
What exactly is it used for?
解决方案
Android Studio uses Lint to check your code for common errors. These are not things that would result in a build error, but violations of best practices or indications of other things that are done incorrectly. The @SuppressLint
command suppresses these warnings.
In this case, you appear to be using a non-static inner AsyncTask class, which can leak a context, so there would normally be a warning about it. Putting that command in suppresses the warning. It is generally preferable to fix the warning rather than suppress it unless you know it is not a real issue.
推荐阅读
- java - 如何通过SQL语句将文件插入AS400
- google-apps-script - 如何在 Google Apps 脚本中记录事件
- bash - base64 解码命令 linux cli 命令
- email - 如何使用 OPENSSL 签署电子邮件并使用 CURL 发送?
- asp.net-core - Razor Pages 中的个人用户设置
- flutter - 如何更改颤振步进器中继续/取消按钮的标签?
- c++ - 为什么 std::chrono::duration 的复制构造函数不是 constexpr?
- python - 如何在继承的 notebook/page/field 中添加字段。奥多 14
- java - 使用可扩展 Listview 的子项打开一个新 Activity
- javascript - 如何查看由 Heroku 上的脚本创建的文件的内容