March 30, 2012

Dev-mode for your Android App

When you develop an App it is often useful to have some switches that allow you to gain more inside into what is going on. The classic example for such a feature is logging. Setting the log to a very noisy level can give you lots of extra information. In Android you can change the log level at runtime using the Android Developer Bridge (adb). Just run adb shell setprop log.tag.<your logtag> DEBUG to enable debug level logging.
But what if you want to bring up extra UI-elements, test different algorithms or even use different backends? A valid approach for this is to use a file that (if it exists) puts the App into dev mode. This works well in Android but is also quite static. A more dynamic switch is available by (ab)using the above log level mechanism. Just define a special logger (e.g. dev-mode) and check if it is set to debug level logging (using Log.isLoggable). This allows you to toggle dev-mode at runtime.
I implemented the above approach for a client who wanted a special dev-version for testing purposes. But in that case the dependence on the AndroidSDK (you need adb) was a concern, so we settled on the property file approach.
If you have any other ideas how to dynamically switch on additional features at runtime, I'd be happy to hear them.

January 23, 2012

ActionBar support

With Ice Cream Sandwich being on the rise now there is really no excuse for not supporting the ActionBar UI pattern anymore, even if you don't support a tablet version of your app. There are quite a few projects out there to help you with that.

Basic support is easily added thanks to the ActionBarCompat sample project that comes with the SDK. You can just copy that over into your project and have a consistent action bar (although very limited) across all Android versions.
It is also a nice example of how to abstract out platform-specific code. And consisting only of a couple of classes it is easy to understand and tweak. There is one little thing you should be aware of, though. The Home button is disabled in Ice Cream Sandwich by default, as described in this stackoverflow question).

For more complete action bar support have a look at ActionBarSherlock.

About Me

codes for a living and also in his freetime, probably for lack of a real hobby. ;-)