@SuppressLint or @TargetApi
来源:互联网 发布:上海公司注册网络平台 编辑:程序博客网 时间:2024/05/21 11:01
@TargetApi
and @SuppressLint
have the same core effect: they suppress the Lint error.
The difference is that with @TargetApi
, you declare, via the parameter, what API level you have addressed in your code, so that the error can pop up again if you later modify the method to try referencing something newer than the API level cited in @TargetApi
.
Having @TargetApi(11)
means that if Lint detects that I am using something newer than my android:minSdkVersion
, but up to API Level 11, Lint will not complain. In this case, that works. If, however, I modified this method to reference something that wasn't added until API Level 14, then the Lint error would appear again, because my @TargetApi(11)
annotation says that I only fixed the code to work on API Level 11 and below, not API Level 14 and below.
Using @SuppressLint('NewApi')
, I would lose the Lint error for any API level, regardless of what my code references and what my code is set up to handle.
Hence, @TargetApi
is the preferred annotation, as it allows you to tell the build tools "OK, I fixed this category of problems" in a more fine-grained fashion.
- @SuppressLint or @TargetApi
- What is better: @SuppressLint or @TargetApi?
- @TargetApi and @SuppressLint
- @SuppressWarinings, @TargetApi, @SuppressLint, @ViewInject
- android TargetApi 和 SuppressLint
- TargetAPI和SuppressLint
- 在低版本的SDK里使用高版本函数@SuppressLint("NewApi") or @TargetApi?
- Android中的@TargetApi and @SuppressLint
- @TargetApi() 与@SuppressLint("NewApi")
- @SuppressLint("NewApi")和@TargetApi()的区别
- @SuppressLint("NewApi")和@TargetApi()的区别
- @SuppressLint("NewApi")和@TargetApi()的区别
- @SuppressLint("NewApi")和@TargetApi(number)使用比较
- @SuppressLint("NewApi")和@TargetApi()的区别
- @SuppressLint("NewApi")和@TargetApi()的区别
- @SuppressLint("NewApi")和@TargetApi()的区别
- @SuppressLint("NewApi")和@TargetApi()的区别
- @SuppressLint("NewApi")和@TargetApi()的区别
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(下)
- sed 命令的使用
- win 访问隐藏文件夹
- Android ActionBar应用实战,高仿微信主界面的设计
- Introduction to the Volatile Keyword
- @SuppressLint or @TargetApi
- C语言基础——预处理
- redis info memory
- JAVA修饰符
- awk 命令的使用
- android 自带的contacts2.db数据库表结构脚本
- 自定义QQ消息红点拖动的效果
- 【ACM之旅】进制转换1 (十六进制转换)
- centos65安装pg935时报错: jade: Command not found