to suppress API level warning, I usually prefer to use @RequiresApi
, than @TargetApi
.
As, @RequresApi
seems newer and better than @TargetApi
, according to RequiresApi vs TargetApi android annotations
But, is there any real use case, where we can solve using @RequiresApi
, but not using @TargetApi
?
@RequiresApi
is more clearly, as described in its doc.
Moreover, @RequiresApi
has FILED Target:
@Retention(CLASS)
@Target({TYPE,METHOD,CONSTRUCTOR,FIELD})
public @interface RequiresApi {
...
while @TargetApi
not:
@Target({TYPE, METHOD, CONSTRUCTOR})
@Retention(RetentionPolicy.CLASS)
public @interface TargetApi {
...
So, @RequiresApi
can be used like:
@RequiresApi(api = xxx)
private Foo bar;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With