Getting Started with Android

Posted By: Kelly Klein on June 22, 2010

Do you have an idea for the next revolutionary or “magical” mobile application that will change the world? Do you want this application to run on the premier open mobile operating system, Google® Android™? Are you not sure where to start or what tools you need? Do you want your application compatible with all the various Android handsets on the market?

If you answered yes to those questions, you are in the right place! This blog post will give you some basic information and point you towards sources to help you in designing your application.

Tools

Android is all about openness. So it should be no surprise that the tools needed to create Android applications are open source and available for the 3 main desktop operating systems, allowing you the freedom to develop your application in the environment that works best for you. Google has come up with a great guide to get the tools you need to get started with Android. It has instructions and links to download and install all the tools you’ll need to develop your new awesome Android application.

Alternatively, Motorola has developed a package called MOTODEV Studio for Android that packages everything you need to get started developing with Android in one package. Included with this package is the MOTODEV Studio for Android plug-in. This plug-in gives you tools that will allow you to sign and export you application so that it is ready for the Android market. You also get tools that allow you to take screen shots of your application in the emulator as well as manage files and database in your emulators or connected devices and much more. If you already have Eclipse installed on your machine and don’t want to download the entire MOTODEV Studio for Android package, you can download and install just the plug-in to your existing Eclipse environment.

Once you have the tools installed and configured you need to have a good grip on some Android fundamentals. Google has a great guide to get you started and will give you a good overview of Android application development.

Application Design Tips

Fragmentation - if you have read about Android development before you’re sure to have run across what people describe as the fragmentation of the Android platform. In about 18 months Android has gone from version 1.1 to 2.1 and is now installed on over 60 different device models. At the time that this blog post was written over half of the Android devices where running a version prior to 2.0. Those 60 devices also have varying screen sizes, screen densities and hardware capabilities. All these factors need to be kept in mind when designing your application.

So how do you design your application to use the newest features of Android while keeping it compatible with older versions of the platform? Reflection is a great solution to this problem. A specific example of this is the Contacts model. The Contacts model for pre-2.0 versions of Android is very different from 2.0+ version. You can still call the older API’s from the new versions of the OS but will not be able to take advantage of the new features that are available to users of the newer OS. In this solution, you would create two wrapper classes one of which would implement the older version of the API while the other class would implement the new version of the API. Once you determine which version of the API your application is currently running you can use reflection to initiate the compatible Contacts wrapper class. For more details about Android and Reflection, see this article.

Views - in an Android application, the user interface is built using View and ViewGroup objects. There are many types of views and view groups, each of which is a descendant of the View class. See this guide from Google for more information about Android Views and UI.

One important thing about the Views for your UI is that they need to be as efficient as possible. There is a real cost to initializing and inflating your layouts and if they are inefficient that cost will be high. It becomes especially bad when you use an inefficient layout in a ListView that contains multiple instances of your view. Check out this series of blog posts by Romain Guy, an engineer on the Google Android project. In this blog series Romain explains how to create efficient views and how to you use the SDK Tools to get some insight into what your views look like to Android:

http://www.curious-creature.org/2009/02/22/android-layout-tricks-1/

http://www.curious-creature.org/2009/02/25/android-layout-trick-2-include-to-reuse/

http://www.curious-creature.org/2009/03/01/android-layout-tricks-3-optimize-part-1/

http://developer.android.com/guide/developing/tools/hierarchy-viewer.html

Motorola has some best practices (with links) for user interfaces with Android that is also very useful:

http://developer.motorola.com/docstools/library/Best_Practices_for_User_Interfaces/

A very helpful tool for creating the XML for your views is DroidDraw.org. This website allows you to drag and drop common layouts and widgets onto a screen and then generate the XML needed to create that view. While it’s not perfect, it does allow you to very quickly get a base outline of what you want your view to be and then allow you to customize it for you needs. And it’s much better than the one default layout editor that comes with Eclipse.

In a future Android blog post we will look specifically at implementing OAuth in your Android application.

Kelly Klein is a Developer for Fellowship Technologies.  He has been with Fellowship Technologies since March 2009.  As a side project with Funkypants Software he developed the Fellowship One for Android application.  He is passionate about serving the Church through technology.

Posted In: Tips,

Comments:
ben hurst said: on May 6, 2011 at 02:43 AM

Kevin, what is your experience of using xml editors to work with xml files, I have been using http://www.liquid-technologies.com/xml-editor.aspx, and was curious as to what your exposure to this has been.

Commenting is not available in this channel entry.