Published using Google Docs
Backward Compatible Android Apps
Updated automatically every 5 minutes

Backward Compatible Android Apps

This codelab will walk you through the steps of building an Android app with a consistent user experience on devices ranging from tablets running the latest version of Android back to simple handsets running Android 2.2 (API level 8).

We’ll cover the following topics:

Step 1: Requirements

This is an intermediate-level code lab and expects a familiarity with creating Android apps.

Please ensure you have the following software installed, can create a new Android project, and run it in the Emulator or on your Android device:

In addition to this we will be using the ActionBarSherlock third-party library.  Please download version 4.1.0 of the library and unzip it somewhere on your computer.

Step 2: Project Setup

We will start with an application created for Android 4.0.3 (Ice Cream Sandwich, API level 15) and extend support back to Android 2.2 (Froyo, API level 8).

Step 3: Become backwards compatible

Change the minSdkVersion attribute in AndroidManifest.xml to allow the app to be installed on API level 8 and newer devices.

Run Android Lint to look for errors

At the end of this step you should see ~80 Lint errors (depending upon your ADT setup)

Step 4: Use API gating

Some new functionality just cannot be backported so we need to gracefully degrade functionality when running on older platforms.  The StackView widget is one example of this.  To remove the widget on older platforms:

Bonus:

At the end of this step you should see ~75 Lint errors (depending upon your ADT setup)

Step 5: Use the Support Package

Google provides a Support Package which includes static implementations of key functionality so that you can use it on older platforms. Go ahead and add it to your project.

Now that we have added the Support Library to the Honeypad project we can start using it.  Support classes aim to be API compatible with the platform implementations.  We need to go through the project switching to use the Support Library:

Bonus:

Step 6: Use ActionBarSherlock

ActionBarSherlock [ABS] provides a back port of the Ice Cream Sandwich Action Bar for devices on Eclair and above.

Now that we have added ABS to the Honeypad project we can start using it.  ABS aims to be API compatible with ICS. We need to go through our project and switch to using ABS:

Bonus:

At the end of this step you should have cleared all Lint errors :-)  Deploy the app to a Froyo phone or emulator to verify.

Step 7: Profit