TargetSdkVersion

From Android Wiki

Jump to: navigation, searcha

The targetSdkVersion attribute tells Android that your app is explicitly compatible with all version(s) of the framework API from minSdkVersion up to the specified value. This lets the system turn off backward-compatibility behaviour introduced in versions after minSdkVersion up to targetSdkVersion, giving you full access to the capabilities (and sometimes restrictions) added in those later versions.

For example, if you set minSdkVersion to 5 and targetSdkVersion to 8, this means that

  • Your app is compatible with all versions of Android with API level 5 (Eclair) and later.
  • When running on systems with API levels 5 to 8, backward-compatibility behaviours for versions prior to 8 will be turned off.
  • When running on systems with API levels 9 or later, backward-compatibility behaviours for versions 8 and later will remain in effect.

Note that you still cannot make simple direct API calls using methods and classes introduced in those later system versions, otherwise your app will fail to load on Android versions older than targetSdkVersion. To access the newer API features, you will need to reference them dynamically at run-time, via the usual Java reflection mechanisms: ClassLoader etc, though it is possible to make the process more efficient with a wrapper class.

Code names for the various Android versions are listed here.

Places Where targetSdkVersion Matters

The following is a list of instances I could find where targetSdkVersion makes a difference to API behaviour.

  • Activity.onKeyDown only tracks the event, deferring the action to key-up in Eclair or newer, but performs the action immediately otherwise.
  • Activity.onPause requires that it be called from the subclass if overridden, but this is only enforced on Gingerbread or later.
  • GestureDetector constructors that omit the ignoreMultitouch argument default it to true if the context is passed on Froyo or newer, false otherwise.
  • App widgets get automatic padding on Ice Cream Sandwich or newer.
  • Tab icons changed in style in Eclair and newer.
  • Android Market filtering for Bluetooth changed in Donut and later.
  • Action-bar support was added in Honeycomb and later.
Personal tools