RequiresApi和TargetApi的android注释

RequiresApi和TargetApi有什么区别?

kotlin的样品:

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

注意:FingerprintManager.AuthenticationCallback需要api M

注2:如果我不使用TargetApi lint失败与错误类需要api级别23 …

解决方法

类似于Mike所说,正如您在文档中可以看到的那样:

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

This is similar in purpose to the older @TargetApi annotation,but more clearly expresses that this is a requirement on the caller,rather than being used to “suppress” warnings within the method that exceed the minSdkVersion.

正如你可以看到的,这实际上是强制调用者来验证调用方法时使用的API,而不是从IDE / LINT中删除警告.

您可以将其与@NonNull或@Null注释进行比较,他们强制调用者可以/不能向函数发送空值.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...