Window->Preferences->Android->Lint Error Checking:
Change NewApi Severity to Ignore.
How to run different code for different SDK levels without errors in eclipse
-
01-06-2022 - |
Question
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
...
}
Solution
OTHER TIPS
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow