views:

76

answers:

1

Howdy, I wrote an application using the Android 2.2 SDK (API level 8). It is running well in the emulator, but now I want it to be compatible to Android 1.5+ (API level 3)or Android 1.6+ (API level 4).

The problem is that it crashes in the emulator when I try to run it on these versions.

What is a good approach to make it compatible to these versions? Is there a way to see which classes/methods cause these incompatibility issues?

+1  A: 

You need to call the features you use not available on a 1.5 device using reflection. See this blog for the basic concept: http://android-developers.blogspot.com/2009/04/backward-compatibility-for-android.html

Fredrik Leijon
So I will have to test each method manually?
Maaalte
Look in the api docs, it lists when a method/class was introduced. if it's newer than api level 3/4 you need a workaround with reflection (or use something else) since your app will crash when the class containing this code is loaded. So run your app and look at the log output to see what causes your problems. Might only be 1 or 2 methods.
Fredrik Leijon
Thanks. I'm on it
Maaalte
If I understand it correctly I would instead of targeting Android 2.2 now target android 1.5 and by using reflections I would add all methods which are available somewhere between 1.6 and 2.2. If this is the case would I not get any disadvantages for compiling for an older version. For example I could imagine that something like a JIT compiler would not work anymore unless I compile my app for 2.2 ?
Pandoro
You can still target 2.2 just set the minSdk attribute in your manifest.
Fredrik Leijon
Okay I found the error. I had an io-method that crashed when no data was found, the 2.2 emulator had the data but the others didn't. Concluded: The hint to take a closer look at the log output made it! Although it took me quite some time.
Maaalte