问题描述
有时候,我区分了code为Android的某些版本可以运行我的应用程序。日食与最新的Android工具还是注意到我的manifest文件允许以较低的Android版本,因此我决定code中有错误。
Sometimes I case out code for certain versions of Android that may run my application. Eclipse with the latest Android tools still notices that my Manifest document allows lower versions of Android and therefore decides my code has errors in it.
解决的办法是添加上面的方法一个 @燮preSS
标记,因此它不会报告错误,或另一种建议是添加 @TargetApi
标记上方的功能
A solution to this is to add a @Suppress
tag above the method so it doesn't report the error, or another suggestion is to add a @TargetApi
tag above the function
我不明白的差异,否则后果
I dont understand the differences, or the consequences
推荐答案
@TargetApi(NN)
说:嘿,Android的!是的,我知道我使用的东西更新不是被允许的东西在我的机器人:的minSdkVersion
这是确定的,但是,因为我敢肯定,我现在用构建
(或东西),使得新的code只能运行在较新的设备。请pretend我的的minSdkVersion
是 NN
本作的目的。(类|法)
@TargetApi(NN)
says "Hey, Android! Yes, I know I am using something newer than what is allowed for in my android:minSdkVersion
. That's OK, though, 'cause I am sure that I am using Build
(or something) such that the newer code only runs on newer devices. Please pretend that my minSdkVersion
is NN
for the purposes of this (class|method)".
@燮pressLint
,以解决同样的错误,说:嘿,Android的!是的,我知道我使用的东西比新被允许什么的我的安卓的minSdkVersion
退出抱怨
@SuppressLint
, to address the same error, says "Hey, Android! Yes, I know I am using something newer than what is allowed for in my android:minSdkVersion
. Quit complaining.".
因此,鉴于 @TargetApi(NN)的选择
或 @燮pressLint
,一起去 @TargetApi(NN)
。在那里,如果你开始使用新的东西比 NN
- 因此您的现有版本,检查逻辑可能是不够的 - 你会得到的再次喊道
Hence, given a choice of @TargetApi(NN)
or @SuppressLint
, go with @TargetApi(NN)
. There, if you start using something newer than NN
-- and therefore your existing version-checking logic may be insufficient -- you will get yelled at again.
这篇关于的Android @燮preSS错误VS @TargetApi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!