PermaLink Android Compatibility Library Supports Fragments but Missing ActionBar/ActionMode08/14/2011
And Google wonders why there's fragmentation of devices and lack of tablet apps :-P

When Honeycomb was first released, they released the interesting concept of Fragments (conceptually like Portlets in the web world) for developing your UI.  This made it harder for app developers because they would have to build a separate tablet version of their app and a different phone version of their app since this new API wasn't for older phone based Android versions.  Google released the promised Android Compatibility Library (ACL) that was meant to address the lack of Fragments API in phone apps, however, this library isn't complete for all the common UI features in Honeycomb.  Most notably, the very useful ActionBar (conceptually like a toolbar in desktop apps) is not supported, so you almost have to rip all the support out of your code to get it to compile for phones, unless you use AndroidBarSherlock which Jake Wharton was nice enough to build on top of ACL (though it doesn't support ActionMode which let you make the ActionBar context sensitive).

A couple of useful tips on this and phone/tablet apps in general:
- Since ActionBarSherlock is included via Android's shared project feature (it can't be done as a JAR file because it has resources that need to be referenced by your app), you have to make sure your resource filenames don't collide with the ones in that library (same is true of any shared projects you include via Properties\Android\Libraries).
- ActionBar, Menu, and MenuItem need to be referenced using android.support.v4.* prefixes instead of android.* prefixes when using the AndroidBarSherlock library.
- To get the action bar in AndroidSherlock, you hae to replace getActionBar() (from the official Fragment API) with getSupportActionBar().
- If you get java.lang.ClassNotFoundException when you try to run your app on phone versions of Android, it means you're referencing Honeycomb or higher APIs (this includes stuff like ObjectAnimator, ClipData, PropertyValuesHolder, etc.) that you need to remove or; unfortunately Java doesn't tell you what class it's looking for.
- If you use methods not in the API version you're running on, you'll get MethodNotFoundException but at least the JVM tells you which method you're failing on in LogCat.
- If you use color or image IDs that are in Honeycomb (e.g., "?android:attr/actionBarSize" or "?android:attr/activatedBackgroundIndicator" in layouts) , your application will blow up inflating those resources when run on smartphones.
- The rest of the caveats are the same as the ACL: all Activities should be FragmentActivities, you need to call getSupport*() instead of get*().
- Yes, you still have to do (android.os.Build.VERSION.SDK_INT > 10) to do special Honeycomb stuff but at least your code is now mostly the same.
- ObjectAnimators aren't available in older phone operating system versions, so if you use this for eye candy, you have to check the SDK version.
- ClipData isn't available on older Android versions so if you're using this for drag/drop, you'll have prevent it from being run on older Android versions.

Comments :v
No comments.

Start Pages
RSS News Feed RSS Comments Feed CoComment Integrated
The BlogRoll
Calendar
March 2024
Su
Mo
Tu
We
Th
Fr
Sa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Search
Contact Me
About Ken
Full-stack developer (consultant) working with .Net, Java, Android, Javascript (jQuery, Meteor.js, AngularJS), Lotus Domino