I know how minSdkVersion
and targetSdkVersion
work, but I need confirmation in this concrete case (I don't want to accidently overlook anything).
My app (game) supports all devices from Android 2.2 and above. Up to now, minSdkVersion
and targetSdkVersion
were set to 8 (i.e. API level 8, which corresponds to Android 2.2).
One of my Views
works significantly smoother if hardware acceleration is turned on for it, but I can't set it in the project, because it requires API level 11. (How did I notice it then? One of my test devices offered a checkbox "force GPU mapping" in Developer Settings, so when I ran my app, I noticed the difference.)
I suppose the solution is to set targetSdkVersion
to 11 (but keep the minSdkVersion
at 8), and from code, check if we're running on API level 11 or above, and then enable HW acceleration for the View (Window). The last step is what requires the higher API level, because otherwise FLAG_HARDWARE_ACCELERATED
is not recognized in the source code.
Assuming all my code uses only minSdkVersion
APIs (except when checking the platform version for exceptional calls at runtime, such as the hardware acceleration), is it guaranteed that there won't be issues on devices below targetSdkVersion
? (Due to the above solution, I mean.) I would like to avoid that my app doesn't work properly on pre-Honeycomb devices. (Note that I test my app on a wide scale of devices in terms of platform versions, too, so testing is not a problem.)
In your Activity
, use this line to set Hardware Acceleration for your window if it is API level 11 or higher:
if( Build.VERSION.SDK_INT >= Build.HONEYCOMB ) {
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
}
EDIT: As an answer for your edit, Android Lint might throw an error saying it is not meant for the TargetSDK, but it will work and not throw any exception for older versions. If it does, the version is somehow > 10, and that cannot be possible.
But you should update your TargetSDK, because by using hardware acceleration, you are aiming for a higher API target.