So you want to write an app

So you’ve decided that you want to start programming applications for your mobile phone.

 Be it for money or purely an interest in development, programming on the Android platform is a fun and simple way to get started in mobile development.

If you are like a growing number of people in the world who own a smartphone  you realize that the smartphone has become more than a simple voice communication tool. It is where you can access all your social networks, emails, calendar, music, videos, entertainment and as much reference material as you need. The smartphone has rapidly become one of the most important devices in our lives.

Consider for a moment what you do before you leave your house;  keys, wallet, mobile phone. These are the three things that you will go back to your house even if it means going back through traffic, uphill with a nasty headwind. The only modern entry on that list, the mobile phone represents our ability to connect with the rest of the world. It is an amazing tool. The average smartphone user has access to more information at their fingertips than most of the people throughout the previous 1000 years of human history hand . That is an impressive assertion, that you can wiki on your smartphone if you would like.

So in a sense the smartphone turns an average person into a superhero. For instance with a wave of your wrist your smartphone can;

Never require that you stop and ask for directions. With GPS and digital maps of the world you can drive right past that creaky gas station and on to grandma’s house. This doubles as a marriage counselor for those spouses whom refuse to stop and ask for directions. Now we don’t have to!

Entertain You. Smartphones have the ability to store hours and hours worth of music and videos. Add in high-speed networks and you have a full multimedia complex at your fingertips.

Make you a “Name That Tune” Superhero. Never again will your mates bug you at the pub for not knowing the tune “Welcome To The Jungle”. Applications running on the smartphone can identify the background music playing and send all the information to you. If you like it, the program will also let you download it for a fee.

Answer Any Trivia Question. With high speed access to the internet over the phone you can literally answer any trivia question within seconds.

Play With You. Smartphones are now coming with advanced graphics and computing processors that can let you play many games right on your device.

All of this is just a sampling of what the smartphone can do. The smartphone can do all these things because it enables mobile applications to run on the device. Mobile applications are really what drives the smartphone usage and most importantly why you are reading this article.

So where do you begin? Well the good news is the mobile application development is much easier today than it was before[1]. I started mobile development back in 2003 on the Motorola i710 handset. It was big, clunky heavy device that had a small screen and almost no data connection. It featured a heavy clamshell design useful for propping doors open or beating off potential muggers. But it was a mainstream device that allowed installation of external J2ME applications and opened the door to a lucrative opportunity to build mobile applications. Creating mobile applications for this device was long, laborious and expensive. Our first application took almost a year to complete all the way through development, certification and testing. Once the application was built there was no simple way to get the application to consumers. Each network operator and carrier had to be sold the application separately and managed their own application store or deck. Each had their own requests and requirements for the application which made it even more difficult to succeed.

But by far the most difficult part was the requirement to port to different handsets. You see handset makers and carriers each decided to interpret their own version of the write-once run-anywhere paradigm. This meant that each device and each firmware version of the device had different features and different restrictions. Imagine having to write a different desktop application for someone with a 15” monitor versus a 19” monitor. With so many device nuances it was often much easier to produce a separate build for each device. This resulted in managing somewhere in the range of a couple of hundred different builds for devices. Any changes in the codebase had to be propagated across the builds which made code management a nightmare scenario.

Luckily some very smart people saw this situation and worked very hard to remedy it. The Android operating system grew out of these platform challenges as a way to simplify and optimize the mobile experience for multiple devices. 

 Of course today things are much different. Mobile platforms are more capable, faster and the development environments provide a much wider range of tools for development. Also if you add in the availability of application stores for marketing your product, mobile development has taken some great leaps forward in terms of simplicity and effort.

Even with all the changes in the mobile development arena the core skills to develop a functional and useful mobile application remain the same. This article is designed to not only give you a good understanding of the Android programming process but also teach the art of programming for mobile devices. Over the next couple of articles we will be creating a full Android application from design to deployment. We will walk through what it will take to build a full application and go over some pitfalls to avoid and shortcuts to make your programming easier.

Unlike gambling, programming for the Android platform is easiest to learn by doing it. Feel free to work through your own application along with the book or follow along with the application that I have created. By the end of the book you should be experienced enough to build, deploy and even make money from the Android platform. At least much more than you would have made by gambling.

What makes mobile programming different?

To see how designing a mobile application is different than a desktop or web application we will compare how the users typically interact with the program and what makes a truly useful application.

Navigation

Consider for a moment the very simple task of navigating through a menu on a desktop or web application. A user will click with their mouse on the menu header and pull down a submenu to highlight the function they are after. In terms of UI design you have to layout the menu components in a logical fashion and make the information easily available. Add some pretty icons and transitions and you are about done, collect $200 advance to go.

The UI model for web and desktop is essentially standardized across the platforms. Whether you run a Windows, Linux or Mac OS they still offer the same windowed application experience. For instance, users have a certain expectation that the close function at the top right (or left) of an active window will close the window and terminate the program. In these applications what you will not see are applications that use as their main input something other than a keyboard or mouse. There are no applications that use an accelerometer for navigating spreadsheets[2] or voice commands for IM.

 

On mobile things are significantly more complicated. There are no fixed set of input devices like a mouse and keyboard. Devices can take input from a keyboard, trackball, touch screen, light sensors, GPS, accelerometers or other sensors. Some devices are designed for one-handed use some require both hands for input. To further complicate matters, devices are not required to have a standardized minimum set of input sensors. That means any application design that you build has to be adaptable to a variety of input sensors if it is to work across many devices.

Of course making a UI that can utilize a variety of input sensors is challenging enough, but in a mobile device you also have to consider that you are constrained by processing power and screen size. This is the main reason why the mobile industry has no standardized UI design. Different UI interfaces add to the complexity of the application and more often than not will require multiple versions of the application to work around the differences. Applications that are intuitive and designed for one device may be obtrusive and unusable on another device with different input sensors. Entering text into a field can be done by T9, physical keypad, touchscreen or even voice input. Menu navigation is equally complex because there is no assumed protocol for opening menus. You could use a trackball, scroll wheel, navigation pad or touch screen. So even in the most basic of features the mobile application has to consider significantly different UI and input constraints for it to be functional.

Just when you thought it could not be any worse, you also have to consider the users themselves will use different sensors for interaction on the device. Some users will prefer to use a keypad rather than the touch screen and that means you need to ensure multiple forms of input are capable for your application. The best mobile applications have a UI that can utilize all the sensors and have multiple points of access for the information.

That is the bad news.

The good news is that device manufacturers and platform companies are trying hard to create a standardized set of interfaces so that applications will run smoothly across a number of devices. Well that is not strictly true. RIM (Blackberry) is working really hard to ensure their platform is consistent. Apple ensures that all Cocoa apps are seamless across their devices. Nokia supports families of devices with consistent interfaces. Windows new mobile platform will do the same.  So if you as a mobile developer wanted to create an application that runs smoothly across all those platforms you will need to create multiple applications and multiple designs, one for each platform.

This inconsistency is what first drew me towards Android. Android is an open source initiative by a number of handset manufacturers, service providers and application developers that creates an environment that standardizes some of the most common navigation and interface elements. All Android devices will require some fixed navigation elements and that is the key to a consistent UI. By using these standardized elements in your design you can eliminate much of the UI complexities and focus on UI features that will enhance your application. What this means to a developer is that an Android application will run the same on a Motorola device as it will on a Samsung device even if the screen sizes, processing power and input sensors are quite different.

Since the device plays such a large part in the success of your application you should consider how to seamlessly integrate your program into the existing platform. The most successful mobile applications will serve to enhance the experience of the platform and device and not duplicate another environment.