Whats the difference between RequiresApi
and TargetApi
?
Sample in kotlin:
@RequiresApi(api = Build.VERSION_CODES.M)
@Target
Both of them are for handling feature added to new android API levels without affecting the other API levels.
RequiresApi
@RequiresApi(api = Build.VERSION_CODES.*api_code*)
Here it says that the annotated element should only be called on the given API level or higher. The annotated element below the given API level won't call.
TargetApi
@TargetApi(Build.VERSION_CODES.*api_code*)
Indicates that Lint should treat this type as targeting a given API level, no matter what the project target is. Only meant for specified API level. Won't called on other API level.