Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RequiresApi vs TargetApi android annotations

Whats the difference between RequiresApi and TargetApi?

Sample in kotlin:

@RequiresApi(api = Build.VERSION_CODES.M) @TargetApi(Build.VERSION_CODES.M) class FingerprintHandlerM() : FingerprintManager.AuthenticationCallback() 

NOTE: FingerprintManager.AuthenticationCallback requires api M

NOTE 2: if I dont use TargetApi lint fail with error class requires api level 23...

like image 411
Daniel Gomez Rico Avatar asked Oct 12 '16 20:10

Daniel Gomez Rico


1 Answers

@RequiresApi - Denotes that the annotated element should only be called on the given API level or higher.

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

like image 121
Abhay Avatar answered Sep 20 '22 22:09

Abhay