Android 目标 API

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24798481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:46:57  来源:igfitidea点击:

Android Target API

androidandroid-4.3-jelly-bean

提问by umamlearn

I try to edit some code. According to the developer note, it's a part of app in android jelly bean version. But i found a piece of code that confusing me. What does this code mean? What's happened if we don't use this or deleting this piece of code:

我尝试编辑一些代码。根据开发人员说明,它是 android jelly bean 版本中应用程序的一部分。但是我发现了一段让我困惑的代码。这段代码是什么意思?如果我们不使用这个或删除这段代码会发生什么:

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)

回答by laalto

It's an annotation that tells the Android Lint tool that the following class or method is targeting a particular API level regardless of what is specified as the min SDK level in manifest.

这是一个注释,它告诉 Android Lint 工具以下类或方法针对特定的 API 级别,而不管清单中指定的最小 SDK 级别是什么。

Lint produces errors and warnings when you're using new functionality that is not available in the target API level. If you know what you're doing and have other mechanisms to prevent the code being run on older API levels, you can use this to suppress the lint errors and warnings.

当您使用目标 API 级别中不可用的新功能时,Lint 会产生错误和警告。如果您知道自己在做什么并且有其他机制来防止代码在较旧的 API 级别上运行,则可以使用它来抑制 lint 错误和警告。

If you remove the annotation, lint uses the manifest min SDK API level setting instead when checking the code.

如果删除注释,lint 会在检查代码时使用 manifest min SDK API 级别设置。

http://developer.android.com/reference/android/annotation/TargetApi.html

http://developer.android.com/reference/android/annotation/TargetApi.html

回答by SuppressWarnings

This is a Java annotation made for android:

这是一个为android做的Java注解:

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)

It tells the lint tool, that the following class / method should only be executed if user is using the application under Honeycomb.

它告诉 lint 工具,仅当用户使用 Honeycomb 下的应用程序时才应执行以下类/方法。