Wednesday, May 5, 2010

Developing Native Android Applications: Not as Hard As You Might Think

Two months ago, my boss asked me to try and build a native Android application based on the mobile website I had created for the university's annual Maryland Day festival. Both he and I are part of an IT initiative in our department tasked with figuring out how best to provide IT services to smartphone users on campus, and while we have in-house expertise in iPhone development, none of us were familiar with what would be involved in building Android applications. So he asked me to give it a shot.

I started by going to the official Android developer site:  http://developer.android.com/index.html. I downloaded the Android SDK per the site instructions, then downloaded and installed the Eclipse plugins for doing Android development, and the files needed to work with the Android API I was targeting in my application. I went through the "Hello World" tutorial, where I learned the basics of starting an Android project in Eclipse, how to configure a simple layout, and how to run the device emulator. After going through a few more of the layout-oriented tutorials, I realized that I was missing out on a few of the concepts being discussed, so I stopped coding and started reading through the development guide pages on the site, where I learned about the different components you can use in Android applications, what they were used for, and how to use them.

After spending the first few weeks just learning from the documentation and the tutorials, I started to focus more of my attention on how to accomplish the tasks I needed to make my particular application work. The developer site didn't have examples that addressed some of the issues I needed to solve, so I starting searching the web. Sometimes I found exactly the answer I was looking for on an Android development forum. Other times, I was able to cobble together an approach based on answers to similar issues on all-purpose tech forums like StackOverflow. I was always able to find at least a clue, something that would point me to the right package in the API documentation. I also had to stray from the Android developer site anytime I needed to learn more about Java coding itself, as it's kind of assumed that the developer is confortable with Java programming (an incorrect assumption in my case).

By the time I was done, I had created a working Android application that:

  • Would check for updated event information at startup by making an HTTP call to an XML page. If the version number on the XML page was higher than the version number stored in the application's database, it would make an HTTP call to a ColdFusion page that output the updated event information as XML, parse the XML with a SAX parser, and update the application's SQLite database with the event data.

  • Provided the user with a number of different ways to find events by interest. Each listing (whether it was a list of events, a list of event sponsors, etc.) would be preceded by a search box, and as the user typed in the search box, the list would be filtered on-the-fly based on the search text.

  • Gave the user the ability to flag an event as a "favorite" by tapping a toggle button on the event detail page, which would update the event record in the SQLite table and allow them to pull up a list of all of their favorite events.

  • Gave the user the option of seeing a satellite map view of where the event was located using the Google Map API, with the event location marked with an particular icon based on what type of an event it was.

  • Gave the user the option of seeing a satellite map view that showed the user their current GPS location on campus and where the particular event was located.  The user's position on the map would be updated as the user made their way towards the event location.

Although it worked pretty well, there were a few minor bugs that I couldn't work out before the festival, and we weren't comfortable releasing it to the public having only been able to test it on particular Android phone model (the Motorola Droid), so it wasn't put into production.

Even though I went into the project with an open mind, I really hadn't expected to be able to build such a full-featured application, not as a first Android application and not with being a Java noob to boot. What made it possible was the excellent documentation on the Android developer site, the development tools within Eclipse (the code hinting/code correction, the automated compiler, the debugger perspective, and the device emulator), and the various tidbits of Android development how-tos out on the web. And thougth there were some moments of frustration, I generally enjoyed the experience.

I don't know how much more native Android development I'll be asked to do at my job, but I plan to create some Android apps on my own time now that I know how. And I plan to start blogging about Android development, not as an expert (I have a lot to learn yet) but as someone who's learning as he goes. So you can expect to see more Android and Android development content on my blog from here on out.

No comments:

Post a Comment