Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Android 4.0 apps backwards compatible?

Android 4.0 (ICS) has lots of new UI guidelines which are great. The problem is that going forward, I'm not sure how to build an app for Android 4.0 and make sure that the app looks the same/similar on devices running Android 2.2 and 2.3.

There is the Android compatibility library, and a backwards compatible Action Bar, but I was looking for a more concrete solution for porting post-ICS apps to pre-ICS phones.

Am I on the right track? Anyone have any thoughts?

like image 314
Shams Shafiq Avatar asked Jan 25 '12 22:01

Shams Shafiq


1 Answers

Here are some suggestions.

First, pay attention to the new Android Design guidelines. I believe this is a good idea, not only good for the obvious design reasons, but also because it will make backward compatibility easier. For example, the Support Package helps bring recommended design elements to old platforms and new revs of this package will likely bring it into closer alignment with the latest design guidelines.


Second, use fragments. Even if you don't think you have much need for fragments now, they are the future of Android design and the number of large screen Androids is likely to grow very quickly. And though they add some extra complexity, I think they encourage good design by separating the view from the activity.

Enable the use of fragments via the Support Package (also known as the compatibility library). This is fairly simple and I have not encountered any problems doing this. Just make sure that your imports look like this:

import android.**support.v4**.app.Fragment;

so that you are getting them from the support package rather then calling the native ICS API's directly.


Third, enable the ICS/HC actionbar using themes as described in the docs. Note that this does not give your app an actionbar on pre-Honeycomb platforms. For that you either need to use something like ActionBarSherlock or the ActionBarCompat sample. Both are good solutions but they add to the complexity of your app. There is no actionbar in the current rev of the support package, and this is apparently due to technical issues, but I would suspect that they are trying to resolve those issues.

So, if you want to keep is simple, consider that it is reasonable for your app to have an actionbar on ICS & HC, and no actionbar on earlier platforms. Actually, the Android Dev blog had a post in the last few days that focussed on managing menus and action items under these circumstances.

Also, consider that adding a pre-Honeycomb actionbar to your app later (e.g. using the code from ActionBarCompat sample) won't be that bad - much easier, in my opinion, then reworking your code for fragments later.

Finally, note that you will need to use a recent SDK so that you can refer to elements such as the holo theme (for the ICS actionbar) and the showAsAction="ifRoom" element, so your manifest will include something like:

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
like image 128
Tom Avatar answered Sep 21 '22 09:09

Tom