Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - How do you support older API's without having 2 compiled .apk files when you use methods from newer API's?

Tags:

android

api

I'd would like to implement multi-touch in my app. Multi touch support wasn't available until API version 5. However, I would also like my app to be backwards compatible until API level 4. Is there a way to get around this, other than creating two separate .apk's in which I remove the multi touch code from the level 4 version?

like image 509
user432209 Avatar asked Feb 25 '23 11:02

user432209


1 Answers

The basic way to use features from a specific SDK version, but still remain backwards compatible, is to create an interface describing the methods you need, then implement that interface for the different SDK versions you want to target. At runtime, you instantiate the correct implementation depending on the Android version (Build.VERSION.SDK).

With respect to multitouch, there was a good article on the Android Developer's Blog about this a few months ago: How to have your Cupcake and eat it too.

like image 95
Erich Douglass Avatar answered Apr 26 '23 22:04

Erich Douglass