ahmetvefa53
ahmetvefa53

Reputation: 611

what is android @TargetApi annotations means

does TargetApi mean that code must be called under a specific version or must be called greater than or equal specific version?for example

TargetApi(23) means that use for (23 and below ) or (23 and above)?

Upvotes: 5

Views: 2919

Answers (2)

Ben Butterworth
Ben Butterworth

Reputation: 28810

From TargetApi docs:

Indicates that Lint should treat this type as targeting a given API level, no matter what the project target is.

It's used purely for the linter. Instead of using targetSdkVersion specified in your build.gradle, it will use this API.

When should you use this?

Perhaps when you're using a deprecated API, but you don't want the linter to continue warning you. You explicitly tell the linter, I know that this is deprecated but I don't care, I am using it as if I was on an older API level. You might (should) also add a comment nearby.

Upvotes: 1

Pavel B.
Pavel B.

Reputation: 824

Target Api 23 means that the annotated method should run only on api 23+ devices. You should use it with IF check for api level of the device. If your app's minimum api level is lower than 23 consider providing a method for older devices.

Upvotes: 3

Related Questions