Psst! Want to Build an App?

As a treat for regular readers this entry is a little departure into my life as one of the world’s foremost Software Developers 1.  A developer is that strange breed of person who likes computer technology and uses it to produce the web sites and applications that users need to get their Internet fix without having to do any of that tedious thinking. We don’t get much human company (or vitamin D) and have “simple” social skills, and assume that everyone loves technology.  If this isn’t you then please move on: it’s going to be a techie-fest from now on because I’m going to write about developing my first phone “app”.  Now we all know that “app” is a word coined by marketing types in expensive suits and nice hair who can’t cope with something as polysyllabic as “computer program”. 2  But if it makes coding look cool once again 3 then who am I to disagree?

I’m going to treat you like informed, consenting adults: if there is something in this blog you don’t understand then I recommend you use a technique called “Googling it” – I’m not here to give you free technical support 4. I also recognise that by this stage only people called “Fenton” are reading, so we can bash on with the juicy technical stuff.

Android Fun

As a switched-on person (it’s dark in here and I can’t see your face, so I’m just guessing) you will have heard of Android – Google’s phone operating system. There is a religious war going on at the moment between Apple and Android. It’s a walled-garden versus open-source zeolots’ mudfest. All a bit silly given that deep down they have the same gene pool (it’s a bit like that great Star Trek schism of the Ba’ku and the Son’a (you were warned! – Ed)). Only the lawyers win, and that’s the last mention of that bunch here. Nowadays everyone is getting excited about apps running on their smartphones and tablets. Stuck here in the basement of Vital Towers I don’t use my phone for voice/text as that would imply a social circle and a decent phone signal. However I am very keen on apps and would like to write about my experiences in developing one in the hope that it might encourage you to do the same. You may have noticed recently that politicians etc are in a froth 5 because all that ICT they get in non-Scottish schools leaves them totally ignorant of how a computer works. Lots of reports and headlines asking how to get our yoof into programming. Note, that in enlightened Scotland they still teach computer science as Darwin intended.

So which religion to follow? Pretty simple: it’s Android, for the following reasons:

  1. I have an Android phone (the sublime Samsung Galaxy S2)
  2. The Android development environment is free.
  3. Android apps are written in Java rather than the excrescence that is Objective-C used by Apple. I messed around with this back in the late 80s and voided my alimentary canal. Masocist fodder. Fortunately, at the time I discovered Smalltalk-80 and life became beautiful again.  Java is a descendant of Smalltalk; Objective-C is some bastard off-spring that should have been drowned at birth.  I also earn my daily crust using C# and with my deteriorating eyesight this looks identical to Java. 6
  4. We don’t need approval from Apple to write what we want.
  5. Err, that’s it.

Getting Started

The really excellent thing about developing for Android is that there are shed-loads (my proposed new SI unit of software volume – symbol is SL) of stuff out there to make your life that bit easier. One essential is the Android SDK that contains all the basic tools you need. It is possible to develop an Android app using the command-line tools you get in the SDK in the same way as it’s possible to perform keyhole surgery with a Swiss Army knife, but who would if there is something better out there? Enter stage left, the Eclipse IDE. This is a free product that makes most professional software look like something your nephew wrote using Sinclair BASIC. It’s slick and smart. It also has an add-in for developing Android apps that integrates with the SDK. Life is looking pretty sweet at this point as you get to click on nice icons rather than type arcane commands.

The only downside is that you have 4.3 SL of software to download and install. This is going to take a while, so put on a big pot of herbal tea (mine comes from Chile made from grapes). You’ll be installing the SDK, the Java run-time, the Eclipse IDE, the Android add-in, the documentation, the kitchen sink. Luckily the documentation is superb and holds your hand through the process (leaving the other hand free to hold your glass (of herbal tea)). It worked beautifully for me, leaving me ready to develop that killer app that would finance my tunnel out under the sentry towers… If it went pear-shaped for you, then may I re-introduce my friend Mr Google.

Hello World

With our disk now full of Android magic and having followed all the setup instructions for the environment and the phone, we are eager to get an app running. Luckily there are lots of decent samples out there to show what it is involved before getting stuck in our own app. I picked a sample called “Notes List” because it looked pretty trivial but covers all the essentials and it’s the plumbing I want to check out rather than this particular app’s features. So I created a new Android project using this sample as the starting point. This happily compiles and I can run in the device emulator. At first I thought it was broken: it’s just very, very slow – it makes a GP receptionist look speedy (are you detecting a seam of recent pain here?).

Android has a nice security feature that requires all apps to be cryptographically signed before they can be installed. As I trust myself 7, I’m happy to create my own certificate and this means using the “keytool” program that comes with the JDK. So at the very first step we leave the nice IDE graphical world and drop down into the command line and some obscure parameters (do I have an “organisational unit”?). A bit of fiddling later and we have our own certificate sitting in its keystore (which you’ll want to backup).

Now we can package up the app ready for the device. You use the Export to Android wizard. This asks you for the keystore you’ve just created and after a bit of whirring and grinding, out pops the app package ready to install. Plug in the phone using its USB connector. Then it’s back to the command line to use the “adb” program in the Android SDK to install the app. A few seconds later and we have a “Success” result. On the phone we find the new app sitting there and a quick click and we’re up and running.

That was a bit more command line fun than I’d expected given how smart the IDE is, but now that we’ve got our key it will be simply an install step from now on. We can live with that. Now the fun starts as we start writing our own app.

It turns out all that emulator tosh is unnecessary: just use the phone! You need to change a few settings on the phone to allow USB debugging and to accept apps not from the Android Store, i.e. stuff signed by dodgy certificates. Then you need a driver to let Eclipse talk dirty to the phone. For me, this involved installing Samsung’s Kies package. You can see they are Korean because they assume everyone has a Gbps connection to download their 3.2SL of junk. They are almost as bad as HP in making you download shed-loads of generic junk because they can’t be bothered localising it. But hey, they let me install it in 2000 different languages – I was sorely tempted to see what Faroese development is like. Finally, all was ready and Eclipse could see my phone as a device. Now clicking on the Run/Debug button installs the app on the phone and off we go. I nearly spilled my glass! It was like a rocket and we were running the app and could do all the great geeky stuff like breakpoints and tracing. Way cool.  It also uses the phone’s hardware to do things that the emulator doesn’t support, e.g. access to the sensors.  So time to write my own stuff: follow the adventure here.


  1. And because my knee is still not back to full walking
  2. And before you write in indignation to the Daily Mail, yes we use the American form for software: “programme” is for what the BBC produces.
  3. As some reports suggest.
  4. Although I am always keen to discuss re-assuringly expensive technical support.
  5. I know this is their default state, but they are keen at the moment on anything that distracts us from the fact that the world is rapidly approaching the event horizon of a big economic black hole and this will do nicely.
  6. Just don’t get me started on Java’s weird capitalisation rules or that bizarre need to use Hungarian notation.
  7. And very few others.