Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the SuppressLint Java annotation?

Tags:

java

android

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?

like image 594
Ambreen Khan Avatar asked Aug 06 '18 16:08

Ambreen Khan


1 Answers

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.

like image 121
Tyler V Avatar answered Nov 12 '22 19:11

Tyler V