Android中的@TargetApi and @SuppressLint
来源:互联网 发布:在线财神网淘宝商城 编辑:程序博客网 时间:2024/05/16 07:16
@TargetApi
这个注解的意思就是告诉Android的Lint工具,下面的类或者方法是与一个指定的API相对应的,忽略manifeset文件里面的minSdk的设置。
假如你不加这个注解的话,当你在用一个较新的api方法时候,如果manifest文件中定义的minSdk比这个方法对应的版本要低,Lint检测的时候会报错误或者警告。
注意这个注解,并不意味着在低版本的sdk中就可以使用高版本的api了,在代码中最好还要加上判断,如:
@TargetApi(11)static public<T> void executeAsyncTask(AsyncTask<T,?,?> task, T...params){if(Build.VERSION.SDK_INT >=Build.VERSION_CODES.HONEYCOMB){ task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,params); }else{ task.execute(params); }}
@SuppressLint('NewApi')
这个注解和上面的差不多,只不过唯一区别是targetApi确定了要忽略的目标api的版本,比如11,假如manifest文件中的minsdk更改过之后这个值可能也要跟着改变,但是@SuppressLint('NewApi')只要设置过之后,就等于在任意api版本都忽略了。
具体Lint的使用和说明,网上有很好的介绍了,我就不重复了:
http://blog.csdn.net/thl789/article/details/8037473
http://blog.csdn.net/thl789/article/details/8036066
0 0
- Android中的@TargetApi and @SuppressLint
- @TargetApi and @SuppressLint
- android TargetApi 和 SuppressLint
- android下的SuppressLint与TargetApi
- 关于android的@TargetApi和@SuppressLint("NewApi")
- @SuppressLint or @TargetApi
- @SuppressWarinings, @TargetApi, @SuppressLint, @ViewInject
- TargetAPI和SuppressLint
- 【Android】高低API版本兼容之@TargetApi与@SuppressLint("NewApi")
- android.annotation包中TargetApi和SuppressLint注解
- Android @SuppressLint("NewApi")和@TargetApi()的区别
- android中的@SuppressLint
- android中的@SuppressLint
- @TargetApi() 与@SuppressLint("NewApi")
- android 基础 @SuppressLint("NewApi")和@TargetApi()的作用与区别
- What is better: @SuppressLint or @TargetApi?
- @SuppressLint("NewApi")和@TargetApi()的区别
- @SuppressLint("NewApi")和@TargetApi()的区别
- 毫秒计时器
- android 耳机线控的实现方法
- Qt_OpenGL:3D旋转自定义换色
- IOS中延时执行的几种方式的比较和汇总
- 16周项目奇因子
- Android中的@TargetApi and @SuppressLint
- kafka Kafka JAVA客户端代码示例
- 在linux系统中配置java环境变量的三种方法
- 动态链接库和静态链接库的区别
- 个性化你的windows8-调整Win8.1窗口边框变窄
- VS2012——LinkIssue: Error 'LINK : fatal error LNK1123: failure during conversion to COFF...
- RecyclerView详解
- spring3mvc与struts2比较
- 合璧儿终于在CSDN开通博客了