Getting Started with Android Development

Unless you have been hiding in the caves for the past couple of months, by now you must have heard of the mobile platform from Google that everyone is talking about. Yes, that’s right, I am talking about Android. Android is an open source mobile operating system that is based on the Linux kernel. Using Android, device manufacturers can customize the OS to suit their particular hardware design, thereby allowing them to innovate without limitations. For developers, Android programming uses the Java programming language, and familiarity with the language immediately opens the platform to every Java programmer in the world.

In this inaugural article of the Android series, I will get you started with Android development without requiring you to wade through pages of technical documentation. At the end of this article, you will have written a simple Android application and you will be able to deploy the application onto an emulator or a real Android device.

So, what are you waiting for? Strap on your seat belt and let the fun begin!

What you need to develop for Android?

Developing for Android is not expensive. All you need is a Mac, or a PC that runs Windows or Linux. For this article, I will use a PC running Windows XP.

The Android SDK is available for free at: http://developer.android.com/sdk/1.1_r1/index.html. At the time of writing, the latest version of the Android SDK is Version 1.1 Release 1. The Android SDK comes with all the tools and APIs you need to write and debug your Android applications. It also includes the Android Emulator, allowing you to test most of your applications without needing a real device. Obviously, for some applications (such as those using the hardware of an Android device like camera, Bluetooth, etc) you would need a real device and the emulator will not fit the bill. As far as real devices are concerned, for developers outside the US the only choice at the moment is to buy the Android Dev Phone 1 (see http://code.google.com/android/dev-devices.html), which costs US$399 (plus a US$25 registration fee for the Android Market).

For developing Android applications, you can use the Eclipse IDE (download free here). Once the Eclipse IDE is installed, you need to install a custom plug-in called the Android Development Tools (ADT). This tool adds Android project support in Eclipse and should be downloaded and installed by all Android developers. For detailed instructions on how to obtain and configure the ADT plug-in in Eclipse, see http://developer.android.com/sdk/1.1_r1/installing.html.

So, here is the summary of the steps you need to perform in order to start developing Android applications:

  • Download and setup the Eclipse IDE
  • Download the Android SDK and then expand the content of the zip file into a folder
  • Install the ADT plug-in in Eclipse
  • Configure Eclipse to point to the Android SDK

Your First Android Application

With all the tools and SDKs setup, you are now ready to embark on the journey to Android nirvana! With Eclipse powered up, let’s create a new Android application.

In Eclipse, create a new Android project and name it as shown in Figure 1.


Figure 1 Creating a new Android project

Take note of the various fields you need to supply when you create a new Android project:

  • Project name – the name of the project
  • Package name – the name of the package. This name will be used as the package name in your Java files. Package name must be fully qualified. The convention is to use your company’s domain name in reverse order
  • Activity name – the name of the activity in your Android application. In Android, think of an activity as a screen containing some actions, hence the name “activity”
  • Application name – the user-friendly name of the application that will be displayed in the Applications tab of the Android UI

When the project is created, the Package Explorer in Eclipse will show the project and its components (see Figure 2).


Figure 2 The content of the Android project

Don’t let the number of items in the project scare you – they are actually very straight forward.

First, the src folder contains your Java source files. The HelloMobiForge.java file is the source file for the HelloMobiForge activity you specified when you created the project earlier. The R.java file is a special file generated by the ADT to keep track of all the names of views, constants, etc, used in your Android project. You should not modify the content of this file as its content is generated automatically by the ADT.

The Android Library contains a file named android.jar. This file contains all the classes that you would use to program an Android application.

The res folder contains all the resources used by your Android application. For example, the drawable folder contains a png image file that is used as the icon for your application. The layout folder contains an XML file used to represent the user interface of your Android application. The values folder contains an XML file used to store a list of string constants.

The AndroidManifest.xml file is an application configuration file that contains detailed information about your application, such as the number of activities you have in your application, the types of permissions your application needs, the version information of your application, and so on.

Modifying the UI of the Application

Let’s now modify the UI of our application so that you can do some useful work. Recall earlier that you had an activity named HelloMobiForge? Double-click on the HelloMobiForge.java file in the Package Explorer to view its content. You should see the following:

Notice that the HelloMobiForge class extends the Activity class. When the activity is loaded, the onCreate() event handler is called. The activity loads its UI from the XML file named main.xml. This is represented by the constant named R.layout.main (generated automatically by the Eclipse as you save your project). If you examine the main.xml file located in the res/layout folder, you should see the figure shown in Figure 3.


Figure 3 The UI displayed graphically

If you click in the main.xml tab located at the bottom, you will see the following:

In Android, the UI of each activity is represented using various objects known as Views. You can create a view using code, or more simply through the use of an XML file. In this case, the UI Is represented using an XML file. The element represents a text label on the screen while the element specifies how views should be arranged. Notice that the element has an attribute named android:text with its value set to “@string/hello“. The @string/hello refers to the string named hello defined in the strings.xml file in the res/values folder. If you examine the strings.xml file, you should see the following (click on the strings.xml tab at the bottom of the screen):

Let’s now modify the main.xml file a little just to have a feel of programming Android. Add the following

18 Comments

  • karthik.itan says:

    thank u. it is a useful article…

  • Dallasite121 says:

    Yes, I am also getting the error “create field id, or constant as id” Not sure what to make of this as I am very very new to the Android SDK

  • coder_xpert says:

    This is a really nice share…!
    CX

  • vijay_amirtraj says:

    Thanks Great tutorial, now my confident level is increased, I hope I may soon become a Mobile App developer. Since I am newbie to this Mobile world.

  • jack22 says:

    really awesome…

  • brkarslan says:

    Hi,

    i need an advice. I’m not a program developer. I just know some programming languages with basic level. (c, html..)
    I saw your article and i wonder that, can i learn and develop a basic android application? I just want to do a basic guide for tourists who are coming to cyprus. There will be some advice, tips and location informations.

    What do you think? Should i know java language to do it? Or can i do it with reading some articles like this one? (when i read this article, i’m so comfortable about do it :)) )

  • swathi says:

    Great tutorial it helped me a lot..

  • akshay.kelkar says:

    I am developing first time android application and i have got a very nice guidelin.

    Thanks a lot

  • insane says:

    I bet this is really good if and when it works, but there has to be an easier way to code a simple Android App?
    Unfortunately Eclipse refuses to accept the Android SDK on my netbook so I’m stuck until I’m back at my regular computer. =/

    It feels kind of overkill to spend days just to get the development environment up and running and even then it has a tendency to crash pretty often. Does anyone know a better way to develop that doesn’t include downloading and installing tons of buggy applications, programs, connectors, add-ons etc?

  • handfire says:

    Excellent tutorial, do you know where can I find more like this?

Exclusive tips, how-tos, news and comment

Receive monthly updates on the world of mobile dev.

Other Products

Market leading device intelligence for the web, app and MNO ecosystems
DeviceAtlas - Device Intelligence

Real-time identification of fraudulent and misrepresented traffic
DeviceAssure - Device Verification

A free tool for developers, designers and marketers to test website performance
mobiReady - Evaluate your websites’ mobile readiness

© 2024 DeviceAtlas Limited. All rights reserved.

This is a website of DeviceAtlas Limited, a private company limited by shares, incorporated and registered in the Republic of Ireland with registered number 398040 and registered office at 6th Floor, 2 Grand Canal Square, Dublin 2, Ireland