Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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.
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.