zoukankan      html  css  js  c++  java
  • (转)在低版本的SDK里使用高版本函数@SuppressLint("NewApi") or @TargetApi?

    @SuppressLint 和 @TargetApi达到的效果是一样的,相对于SuppressLint ,TargetApi会根据函数里使用的API,严格匹配SDK版本,给出编译错误,但是SuppressLint 则忽略了SDK版本。

    例如:

    [java] view plaincopy
     
    1.      @TargetApi(Build.VERSION_CODES.FROYO)  
    2.     public static File getExternalCacheDir(Context context) {  
    3.         File dir;  
    4. //        if (!VersionUtils.hasDonut()) {  
    5.         if (!VersionUtils.hasFroyo()) {  
    6.             dir = new File(Environment.getExternalStorageDirectory().getPath()  
    7.                     + "/Android/data/" + context.getPackageName() + "/cache/");  
    8.             if (!dir.exists() && !dir.mkdirs())  
    9.                 dir = null;  
    10.         } else {  
    11.             dir = context.getExternalCacheDir();  
    12.         }  
    13.         return dir;  
    14.     }  

    如果把VersionUtils.hasFroyo()改成VersionUtils.hasDonut()则会报编译错误,如果是@SuppressLint("NewApi") 则不会提示错误。比较严谨的角度讲,更加推荐TargetApi

    原文地址:http://blog.csdn.net/hero_yin/article/details/23081129

  • 相关阅读:
    powerdesigner
    UML类图几种关系的总结(转载 http://blog.csdn.net/tianhai110/article/details/6339565 )
    vuex
    options请求(复杂请求)
    Vue 编程式的导航
    JS定义类
    cors中间件
    vue axios
    restframewor 版本(version)
    pycharm 安装vue
  • 原文地址:https://www.cnblogs.com/yxnchinahlj/p/4595388.html
Copyright © 2011-2022 走看看