Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to maintain backwards compatibility while utilising Android API Level 15?

Ice cream sandwich introduced a lot of new UI design elements but market penetration is still only 4% or so. If one wanted to future-proof their application and utilise some of the design elements introduced with Honeycomb/Ice Cream Sandwich, such as the action bar, the colour scheme etc., what would be the best way to ensure you maintain some modicum of backwards compatibility?

like image 255
stephenfin Avatar asked Apr 10 '12 18:04

stephenfin


People also ask

How can Android help developers ensure backward compatibility in their apps?

In order to provide backward compatibility, developers can check at runtime the platform version and use a new API on newer versions of the platform and old API on older versions or, depending on the case, using some static libraries which offer backward compatibility.

Why backwards and forward compatibility is needed in Android development?

Forward compatibility is important because many Android-powered devices receive over-the-air (OTA) system updates. The user may install your application and use it successfully, then later receive an OTA update to a new version of the Android platform.

What is backward compatibility API?

An API is backwards compatible if a client written against one version of that API will continue to work the same way against future versions of the API.


3 Answers

While I agree with @Ollie C, I think there are other options to add other than just using the Actionbar Sherlock library, while saying this I actively participate in the ABS community and agree it is fantasmagoricly really useful and contains all the UI assets will probably need.

You could look at graceful degradation of UI components back through the API levels. So for example:

You could create in the values folder and set the style like so

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyAppTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <!-- Any customizations for your app running on pre-3.0 devices here -->
    </style>
</resources> 

Then for Android 3.0+ devices, create values-v11 folder:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyAppTheme" parent="@android:style/Theme.Holo.Light">
        <!-- Any customizations for your app running on 3.0+ devices here -->
    </style>
</resources>

And for 4.0+ devices, create values-v14:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyAppTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
        <!-- Any customizations for your app running on 4.0+ devices here -->
    </style>
</resources>

REF: http://android-developers.blogspot.co.uk/2012/01/holo-everywhere.html, How to use Holo.Light theme, and fall back to 'Light' on pre-honeycomb devices?

There is also this project: https://github.com/ChristopheVersieux/HoloEverywhere that it attempting to bring the holo theme.

Finally; Google encourage the developers to include UI components from the SDK to help with the backward compatibility issue, rather than referencing them directly from the Android OS. While this is not your question, it does help provide some consistency.

like image 176
Graham Smith Avatar answered Jan 19 '23 14:01

Graham Smith


This is a very, very broad topic. The answers vary depending on what specific element you're trying to use.

-For the ActionBar: If you want an ActionBar in earlier versions, ActionBarSherlock is a popular, free library extended from the Android support library.

-For the Color scheme / theme: As described in this SO thread, create a res/values/styles.xml and res/values-v11/styles.xml, (for instance, called "myStyle"), for each style pick a relevant parent. For V11, it would probably be "Theme.Holo", wheras for the other, probably "Theme.Dark". Add any customizations you want to the themes. Reference that custom theme in your manifest, and the right one will be chosen depending on the platform version of the device (values-v11 folder will be used for Honeycomb and up, the other for Gingerbread and below)

-For other platform features, you can encapsulate platform-specific functionality in separate classes, and access them based on the value of Build.VERSION.SDK, as described on the android developer blog.

like image 21
Alexander Lucas Avatar answered Jan 19 '23 15:01

Alexander Lucas


http://www.actionbarsherlock.com

This (free) library is brilliant, and provides what you are looking for on prior Android versions.

like image 39
Ollie C Avatar answered Jan 19 '23 15:01

Ollie C