关于androidmianfest中的targetSdkVersion属性

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8"

android:maxSdkVersion="10"

/>

min和max都很好理解,target官网的解释是:

android:targetSdkVersion

An integer designating the API Level that the application targets. If not set, the default value equals that given to minSdkVersion.

This attribute informs the system that you have tested against the target version and the system should not enable any compatibility behaviors to maintain your app's forward-compatibility with the target version. The application is still able to run on older versions (down to minSdkVersion).

As Android evolves with each new version, some behaviors and even appearances might change. However, if the API level of the platform is higher than the version declared by your app'stargetSdkVersion, the system may enable compatibility behaviors to ensure that your app continues to work the way you expect. You can disable such compatibility behaviors by specifyingtargetSdkVersion to match the API level of the platform on which it's running. For example, setting this value to "11" or higher allows the system to apply a new default theme (Holo) to your app when running on Android 3.0 or higher and also disables screen compatibility mode when running on larger screens (because support for API level 11 implicitly supports larger screens).

There are many compatibility behaviors that the system may enable based on the value you set for this attribute. Several of these behaviors are described by the corresponding platform versions in theBuild.VERSION_CODES reference.

To maintain your application along with each Android release, you should increase the value of this attribute to match the latest API level, then thoroughly test your application on the corresponding platform version.

Introduced in: API Level 4

大意是,如果targetSdkVersion等于当前android api的版本,系统就不做兼容性测试了(相对来说程序运行效率会高一些)

target其实是指目标版本(你所期望的版本),target其实包含了指定版本的一些特性。如果你为一个低版本的sdk指定了一个高版本的target,系统就会认为,你的目标版本比较高,然后不会帮你做兼容性测试。例如4.X系统已经不支持menu,此时运行程序,自然就不会出现menu了。

但是如果你指定了target为9(2.3),系统就为认为,你期望的版本的2.3,此刻运行在4.x系统上,依旧会看到menu.

简单来说,target就是你的期望版本

if(sdk<target)

  系统会做一些兼容性处理

else

  就不会做任何处理了(target处理向前兼容的问题)

参考:

http://blog.csdn.net/benbmw2008/article/details/8203583

http://384444165.iteye.com/blog/1738911

posted @ 2013-04-17 19:47  西瓜君  阅读(1753)  评论(0编辑  收藏  举报