Android Target API

umamlearn picture umamlearn · Jul 17, 2014 · Viewed 20.5k times · Source

I try to edit some code. According to the developer note, it's a part of app in android jelly bean version. But i found a piece of code that confusing me. What does this code mean? What's happened if we don't use this or deleting this piece of code:

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)

Answer

laalto picture laalto · Jul 17, 2014

It's an annotation that tells the Android Lint tool that the following class or method is targeting a particular API level regardless of what is specified as the min SDK level in manifest.

Lint produces errors and warnings when you're using new functionality that is not available in the target API level. If you know what you're doing and have other mechanisms to prevent the code being run on older API levels, you can use this to suppress the lint errors and warnings.

If you remove the annotation, lint uses the manifest min SDK API level setting instead when checking the code.

http://developer.android.com/reference/android/annotation/TargetApi.html