Liminal Existence

Easy Android

Let me start by saying that I’m very impressed with Android, and the ease with which I was able to scratch an itch was impressive. The fact that I’m not locked into Apple’s app store world is nice; I don’t know what the specific terms are for Google’s marketplace (I haven’t signed up yet), but frankly I trust them more than I do Apple.

Full Disclosure: at Social Web Foo, Joshua very kindly gave me (and about 50 others) a free Android Dev Phone. He gave strict instructions to actually write something for it, and I probably wouldn’t have bought a dev phone (nor written <shudder> the Java against the emulator), so the fact that I have done so worked out.

I hadn’t written a line of Java before. Shock, horror. It’s just as annoying as everyone always said, but developing for Android with Eclipse is pretty straightfoward. The documentation is good. I started with the basics, and pretty quickly moved to example code. Most notably, the NotePad application that comes bundled with the Android SDK.

Once the Eclipse and the SDK was downloaded and installed, it only took about five minutes to get my first app up and running. Getting a list view of hard-coded data took another ten minutes, and modifying the code to display a different view when one of the items was clicked took about two hours (keep in mind that I was learning Java with the patience of a Ruby programmer here).

The Bad

Honestly, there’s not a lot that I was upset by. Coming from Rails, defining table structures and setters and getters and all the explicit typing is pretty annoying. Cutting and pasting code meant that I had a few mismatched data structure definitions, and the error messages were less than useful, since all that fancy type matching means that when something doesn’t match up in your XML configuration file, Java can’t tell you where to go to fix it. Figuring out where I had mismatched strings in XML config files easily took another couple of hours, which sucked, but it seems like the kind of thing that you’d get used to. Functional brain damage, I suppose.

The Good

Android is a developer’s platform. The way that content, and well, everything is addressed is fantastic. There are hooks for everything, and the tutorials encourage you to do the right thing out of the box. The documentation really only makes sense once you get it, but for the really simple app I’ve been working on, the examples were more than sufficient to get things going.

Basically, every data source is addressable through a ”content://” URI scheme. What that means is that any application can provide hooks (if they know about your data source) to view, edit, or list bits of data. I expose a set of short recipes (from @cookbook) at content://org.romeda.provider.Cookbook/recipes. That means that as long as, say, Tweetie knows that there’s the provider exists, they could add a hook to allow people to add any tweet as a recipe. It also provides hooks for other applications to know when new recipes are published (or, for example, I could tie into a Twitter provider on the phone and piggyback discovery of new updates to that, rather that running my own polling process), in addition to hooks to view, edit, or any action you can imagine.

The best thing about this is that the whole system works the same way. You register an “Intent”, and the OS lets you know when something in the system is relevant. The simplest (but seriously awesome) example of this is if you want to intercept an outgoing call and rewrite the number (or just make the call over a voip stack, for example). You just register your intent to handle ACTION_NEW_OUTGOING_CALL, and away you go. A simple data passing interface lets you receive and attach data to the messages.

The other thing that’s great about Android that I noticed right away is that the default views are extremely simple to use and customize, and they save their own state. Without writing any special code to remember where a user is in the scroll buffer, and without doing any work to remember which view a user was in (e.g., list or item view, edit, etc), the default behaviour is to remember. It’s the embodiment of everything Google’s been doing on the web lately — don’t save, ever, because saving is stupid. Either you’ve published/archived/sent/deleted something, or it’s in a draft form. The draft is implicitly persistent, and avoids the user ever losing work. This is in stark contrast to the iPhone, where Safari’s horrible constant reloading of pages boggles the mind, and burns through roaming data minutes like there’s no tomorrow.

The Code

So it’s not fancy, and it doesn’t even fetch the recipes yet, but I’m posting the code here since it’s pretty damned simple at this point, and demonstrates making an app with two views. I’ll update it as time allows.