简体   繁体   English

Android targetSdkVersion行为

[英]Android targetSdkVersion behavior

I am confused about the requirement/behavior of targetSdkVersion . 我对targetSdkVersion的需求/行为感到困惑。 As far as I understood, setting the target SDK to a particular version indicates that behavior of the application (UI) is ensured up-to that particular version. 据我了解,将目标SDK设置为特定版本表示可以确保该特定版本的应用程序(UI)行为。

In my application, I had set my targetSdkVersion to 1 (for testing) and I have some buttons in my page. 在我的应用程序中,我已将targetSdkVersion设置为1(用于测试),并且页面中有一些按钮。 What I expected was, there will not be any ripple effects in button click (which was introduced in later versions of Android). 我所期望的是,按钮单击(在更高版本的Android中引入)不会产生任何连锁反应。 But there was a ripple effect when I clicked the button. 但是,当我单击按钮时,会产生连锁反应。

Application was running on lollipop . 应用程序正在lollipop运行。

Can any one explain how this works. 谁能解释一下它是如何工作的。

There are three SDK levels of note: 注意以下三个SDK级别:

  • targetSdkVersion : this is a hint to Android of what version the app is designed to run on. targetSdkVersion :这是向Android提示该应用程序旨在运行的版本。 An example of it relevance is that if you set targetSdkVersion to 22 then android will not enforce permissions introduced in version 23 ... and if you up targetSdKVersion to 23, android takes this as an indication that you app knows how to handle system permission requests. 与此相关的一个示例是,如果将targetSdkVersion设置为22,则android将不会强制实施版本23中引入的权限...并且如果将targetSdKVersion设置为23,则android会将其视为您的应用知道如何处理系统权限请求。

  • minSdkVersion : the minimum version (that you say) you app will run on. minSdkVersion :您的应用将运行的最低版本(您说)。 play will not show the app to users on a lower version. 播放不会向较低版本的用户显示该应用。

  • compileSdkVersion : this is the version your app is compiled against. compileSdkVersion :这是您的应用程序针对的版本。 You need to download the relevant SDK to build against. 您需要下载相关的SDK进行构建。 This is the variable the would have the effect you expect in the example above. 这是变量,可以在上面的示例中起到预期的作用。 As the relevant system apis wont be available to your app. 由于相关的系统api对您的应用程序不可用。

The targetSDK in my opinion will not matter the behavior of your app.It is just the API level and does not deal with the user Interface part. 我认为targetSDK不会影响您的应用程序的行为,它只是API级别,并不涉及用户界面部分。

An integer designating the API Level that the application is targetting. 一个整数,指定应用程序要定位的API级别。

With this attribute set, the application says that it is able to run on older versions (down to minSdkVersion), but was explicitly tested to work with the version specified here. 设置了此属性后,应用程序会说它能够在较旧的版本(最低至minSdkVersion)上运行,但经过了明确测试,可以与此处指定的版本一起使用。 Specifying this target version allows the platform to disable compatibility settings that are not required for the target version (which may otherwise be turned on in order to maintain forward-compatibility) or enable newer features that are not available to older applications. 指定此目标版本可以使平台禁用目标版本不需要的兼容性设置(否则可以启用该功能以保持前向兼容性)或启用较旧的应用程序不可用的较新功能。 This does not mean that you can program different features for different versions of the platform—it simply informs the platform that you have tested against the target version and the platform should not perform any extra work to maintain forward-compatibility with the target version. 这并不意味着您可以为平台的不同版本编程不同的功能,它只是告知平台您已经针对目标版本进行了测试,并且平台不应执行任何额外的工作来维持与目标版本的前向兼容性。

Hope this helps mate!!Cheers Happy Coding 希望这对伴侣有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM