Archive for category Getting Started

Finding Sample Code

androidopensourceWhen coding for Android, one problem is finding working example code. This is because the Android APIs have changed over time and what some 3rd parties may have documented last year won’t necessarily work with the new SDK.

Many of the Android forums and blogs seem to have lost their momentum and have very little new material since early to mid 2008. This is because Google took a long time to release the Android 1.0 SDK.

Another problem is that there are fewer official source code samples compared with say S60, iPhone, Java ME and Windows Mobile.

On the positive side, it’s actually very easy to code for Android. The only missing feature is still a resource editor. You have to code the UI yourself using XML. Alternatively try the 3rd party DroidDraw. It will get you going and before long you will find you will be able to code resources by hand. Alternatively, with just a little more effort, you can create controls dynamically in the code.

My experience is that Java ME code doesn’t port that easily. There are too many different concepts and classes. However, non mobile Java, (desktop and server) ports more easily and many open source utility libraries/classes work well. However, beware of relying on these as there’s often an in-built Android equivalent you can use.

The lack of examples can also be solved by viewing the Android source code that includes many of the in-built applications. The Android web pages fool you into thinking you need Linux and to install lots of convoluted tools. However, it’s possible to download compressed snapshots of projects…

Go to…

http://git.source.android.com/

Apps have path platform/packages/apps/xxxxxxx.git

Click on git and select snapshot to get .tar.gz

You can now view these on a Windows PC with an application such as 7-Zip.

There are projects for the alarm clock, browser, calculator, calendar, camera (oh, somebody please work on that G1 shutter lag!), contacts, email, Google search, HTML Viewer, IM, MMS, music, the phone, sound recorder, sync and the voice Dialer.

If you are feeling adventurous you can also download the Dalvik implementation. As with most JVMs, it is itself written in Java! Only a small proportion is actually c.