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.

1 comment:

Anonymous said...

I look for a file in /sdcard/.myapp/config.json which contains additional settings. That allows not only dev mode, but also setting proxy servers, timeouts and other relevant behaviour.

Sadly the same approach on iOS can't be used. There the application sandbox has to be edited (like /data on Android). At one point I did toy with media filenames (eg your music library having a song titled "My-App-Debug-Mode-is-3").

About Me

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