With the Spore Grant project ramping up into full speed it was high time I get setup for Android development. Below are the steps I followed to get a Hello World app up in about the amount of time required to download the Eclipse IDE and the Android SDK. I followed the steps detailed in this awesome article, http://mobiforge.com/developing/story/getting-started-with-android-development. If you want to get started with android development (as the name implies) I would head over there. My purpose for posting this is simply to show what changes I made along the way.

Setup Eclipse for Android Development

Starting an Android Project

First open up the java perspective. Either by Window > Open Perspective > Other > Java or through the open perspective icon in the top right corner. Then you can create a new Android Project.

Enter in the following values in the new Android Project Window

Project Name: The name of the project (i.e. HelloAndroidWorld)
Package Name: Name of the package used in your Java files. The convention is your domain name backwards. (i.e. com.deanverleger.HelloAndroidWorld)
Create Activity: Name of Android Activity. Mobiforge says an activity in Android is basically ‘a screen containing some actions’

After targeting the version of the SDK you want to devlop for (my phone currently uses 2.1.1) hit finish to create your project.

Examine The Package

View the package explorer on the left to see what files have been created.

HelloAndroidWorld.java found in SRC > and then your specific package name is the source file. Important points: HelloAndroidWorld extends the Activity class and runs the onCreate method when the activity is first created. A view is setup in this method “setContentView(R.layout.main);”. This refers to the XML file, main.xml, found in res > layout.

The Android Dev guide states that a layout is the “architecture for the user interface in an Activity” and that they can be created either programmatically at runtime or through declared UI elements in xml files. Our starter program uses the latter method.

Opening up our main.xml file first shows us a graphical representation of our application. Switching over to code view (the main.xml tab at the bottom of the window) allows us to edit the xml file.

In our xml file we see a LinearLayout element that holds our TextView. Notice the line in the TextView that says, android:text=”@string/hello”. This is setting the text value for our TextView to a previously declared value. This value is stored in the XML file, strings.xml, stored in res > values. Open this file up.

We now see the line Hello World, HelloAndroidWorld! which holds the text tied to the “hello” name.

Let’s make a second string named description that gives the a short description, “This is my first Android Application!”.

Let’s go back to main.xml file and add a new TextView for our “description” string. We can basically copy the previous TextView, paste it below the first, and change the text, android:text=”@string/hello” to android:text=”@string/description”. Switch to graphical layout and see what happened (make sure you save strings.xml or you’ll get an error).

Note: the file, R.java, found in gen > your-package-name is not to be edited and is generated automatically each time you save. If we view this file now we see a reference to our description string.

Saying Hello

Now comes the fun part, loading the application in an emulator. Hit F11 to debug/run the application. An error message should pop up saying there aren’t any Virtual Devices found. Hit yes to make one. We can now add a new virtual device. When adding a device there are only two important values for now: Name and target. I named mine “emulator” and set the target to “Android 2.1 …”. We should now have a new Android Virtual Device to use.

Go ahead and hit the x on this window, bringing up a new window “Android Device Chooser” Maker sure you hit refresh in the lower part of the window to find your emulator.

After hitting Ok, eclipse has to load the emulator and then install your application. This will take a while. Watch the output window to see what’s going on. After a long wait we finally get to see our application in action. Hooray!