Pergunta

Inside a method I run a line which is different for different SDKs. And the lint marker always marks it as an error and suggests me to add a new api annotation for the whole method, but this is only one line of code I think it's pointless to create a new method just for this.
I have this in many places, but for example :

private void methodA(){

  ... 
  some code (that is good for both) 
  ... 

  if(Build.VERSION>SDK_INT >= 16)
    pb.setBackground(anim);
  else
    pb.setBackgroundDrawable(anim);

  ...
  more code
  ...
}
Foi útil?

Solução

Window->Preferences->Android->Lint Error Checking:

Change NewApi Severity to Ignore.

enter image description here

Outras dicas

In Eclipse, you have to use an annotation or disable the inspection completely.

If you used the new Android Studio, however, you wouldn't have this problem. It will understand that the code under the if block will run only if the API level is >= 16, and will check the methods accordingly.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top