1. 程式人生 > >Android配置檔案中標籤

Android配置檔案中標籤

SYNTAX:

    <uses-sdk android:minSdkVersion="integer"
              android:targetSdkVersion="integer"
              android:maxSdkVersion="integer" />

ATTRIBUTES:
android:minSdkVersion

An integer designating the minimum API Level required for the application to run. The Android system will prevent the user from installing the application if the system’s API Level is lower than the value specified in this attribute. You should always declare this attribute. If you do not declare this attribute, the system assumes a default value of “1”, which indicates that your application is compatible with all versions of Android.
是一個標示該應用可以執行的最小API級別。也就是說,如果想把這個應用安裝到某個Android系統中,而如果該Android系統的API級別比這個引數小,那該Android系統就不會允許你安裝成功這個應用。所以,你開發的時候,應該指定好這個屬性,免得到時候你的應用在某低版本Android系統中使用高版本API的時候,應用就崩潰了

。若不設定,則預設為“1”,即可以在任何API級別的Android系統上執行。

android:targetSdkVersion

An integer designating the API Level that the application targets. If not set, the default value equals that given to minSdkVersion.
targetSdkVersion意味著你 該應用最想在哪個API版本上執行。若不設定,則預設等於minSdkVersion這個引數關於到你程式碼的API級別與執行時的系統的級別之間的商量權衡問題

這篇文章舉例說明了minSdkVersiontargetSdkVersion之間的關係。如圖:
這裡寫圖片描述

If the API level of the platform is higher than the version declared by your app's targetSdkVersion, the system may enable compatibility behaviors to ensure that your app continues to work the way you expect.

只要 APK 的 targetSdkVersion 不變,即使這個 APK 安裝在新 Android 系統上,其行為還是保持老的系統上的行為,這樣就保證了系統對老應用的前向相容性。

所以,我們可以猜測到,如果 Android 系統升級,發生這種相容行為的變化時,一般都會在原來的儲存新舊兩種邏輯,並通過 if-else 方法來判斷執行哪種邏輯。果然,在原始碼中搜索,我們會發現不少類似 getApplicationInfo().targetSdkVersion < Buid.XXXX 這樣的程式碼。
來自

這篇文章

To make your activity look like a dialog box:
這裡寫圖片描述
To make your activity has a transparent background:
這裡寫圖片描述