Sometimes I case out code for certain versions of Android that may run my application. Eclipse with the latest Android tools still notices that my Manifest document allows lower versions of Android and therefore decides my code has errors in it.
A solution to this is to add a @Suppress
tag above the method so it doesn't report the error, or another suggestion is to add a @TargetApi
tag above the function
I dont understand the differences, or the consequences
@TargetApi(NN)
says "Hey, Android! Yes, I know I am using something newer than what is allowed for in my android:minSdkVersion
. That's OK, though, 'cause I am sure that I am using Build
(or something) such that the newer code only runs on newer devices. Please pretend that my minSdkVersion
is NN
for the purposes of this (class|method)".
@SuppressLint
, to address the same error, says "Hey, Android! Yes, I know I am using something newer than what is allowed for in my android:minSdkVersion
. Quit complaining.".
Hence, given a choice of @TargetApi(NN)
or @SuppressLint
, go with @TargetApi(NN)
. There, if you start using something newer than NN
-- and therefore your existing version-checking logic may be insufficient -- you will get yelled at again.