On Writing for Android
Android is Google’s operating system for phones. Now that I’ve released Life Counter on the Android Marketplace, I’d like to write a bit about the platform and learning it.
-
The documentation isn’t great, which is a shame since most of the classes are pretty easy to use. The tutorials don’t teach you enough to bootstrap and the Framework Topics section, while interesting, doesn’t give a good overview of the system. Framework Topics will also usually cover the way you do things with imperative statements, instead of the declarative XML, which is what you should usually use.
The javadoc is generally OK, but sometimes it shines. Activity, for example.
I was only really able to “get” the Android API because of a separate book I bought. Hello, Android by Ed Burnette walked through multiple non-trivial Android programs and showed off various things I wouldn’t have encountered otherwise. Also, 3rd party tutorials tend to help quite a bit.
-
Android shipped with nowhere near enough widgets in the standard library. There are a lot more widgets in the
com.android.internal.widget
namespace. While you won’t want to use those directly in your project, all the android code is thankfully released under the Apache License, Version 2.0. Check out the code for the base framework and copy classes and resources you want into your project’s namespace. For example, Life Counter’s spin button is copied fromcom/android/internal/widget/NumberPicker.java
. -
XML layouts can be confusing, especially figuring out how to properly space different elements. Like
overflow:hidden;
solves most problems with IE in CSS, the magic XML attribute that your layouts are missing isandroid:layout_weight="1"
. Good luck finding out what that actually means, since the javadoc for android:layout_weight is empty. The only place I’ve found a reasonable description of that property is, oddly, in a section of the Notepad tutorial. I learned this more by trial and error than anything else. -
Total time to make Life Counter: 2 weekends (with small, scattered chunks of freetime during the week) from start to finish, including most of the time spent learning various parts of the android API.