0

I have written an app for android, and I want to make it compatible to new and old versions of android.

For instance there's the CursorLoader class that exists since API 11.

What I would like to achieve is to use the CursorLoader if the device runs with an API >=11 and use the deprecated managedQuery method if the device runs an older version.

What is the recommended approach in this case?

Thanks in advance

richardtz
  • 4,993
  • 2
  • 27
  • 38

3 Answers3

3

I believe cursor loader is included in the support library (CursorLoader).

To add the support library to your project:

  • (In Eclipse, right click your project -> Android Tools -> Add Support Library...).
  • Make sure you set your minSDK and targetSDK in your manifest. You should always target the highest available SDK (16 at this time).

Example pertinent part of the manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.my.app"
    android:versionCode="1"
    android:versionName="1.0.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

If you insist on not using the support library you can do things like

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    /* Perform ICS method */
} 
else {
    /* Perform backwards-compatible method */
}

in your code.

James McCracken
  • 15,488
  • 5
  • 54
  • 62
1

You can use the android support library to be able to use the CursorLoader in API 4+

dymmeh
  • 22,247
  • 5
  • 53
  • 60
0

If you publish on google play you can upload different apk's for different API levels yet as the others stated go for the support library and dont hassle with different implementations for different API levels. So far for me the support library works very well and you dont have to deal with finding out how things where done in the old days ;-) (a knowledge which will be completely useless soon ...)

dorjeduck
  • 7,624
  • 11
  • 52
  • 66