Android Overview Tutorial: Hello World!

PrevMain 

Once you’ve installed the ADT Plugin, you are ready to create your first Android application. The ‘Hello World’ is a sort of a norm in the developer world for beginners, so let’s build and run an android app which does just that – print the golden words ‘Hello World’ on the Android simulator.

First Android Application

Creating Hello World Android Project

In Eclipse, choose File -> Android Project

New Android Project

Name the project ‘Hello World’ and leave all other settings as default.

New Android Project1

Choose the appropriate Android version for your project. In this case, let’s go with Android 4.0 that we installed in the last section.

New Android Project2

The Wizard then prompts you to enter a package name for the Android project. Enter a valid package name and leave all other attribute settings as default.

New Android Project3

Click Finish – your Hello World Android project is almost done!

Creating Android AVD

To run an Android project, you need to create an Android Virtual Device (AVD) first. To do so, select Window -> AVD Manager and click the New button.

Android Virtual Device

Alternatively, click on the AVD Manager in the Eclipse toolbar as shown below.

Android Virtual Device1

Click on ‘New’, choose an appropriate AVD name and target Android version and then click on the ‘Create AVD’ button.

Android Virtual Device2

The new AVD would then show up in the AVD Manager list as shown below.

Android Virtual Device3

Adding Hello World Logic

By default, Eclipse will create a blank Android application which prints nothing. We need to add our own logic in order to print ‘Hello World’ string. To do so, open the HelloWorldActivity.java file located under Hello World -> src -> com.learncomputer in the package explorer window on the left.

Adding Logic to Java  Project

Most developers prefer seeing line numbers against each line of code. To show line numbers, right click on the divider between the left and the right panel and select ‘Show Line Numbers’.

Adding Logic to Java  Project1

This would turn on the line numbers as shown below.

Adding Logic to Java  Project2

After line number 10 (highlighted above), let’s remove line #11 and add the following lines (shown in highlighted text below) to print the ‘Hello World’ string.

Adding Logic to Java  Project3

At this point of time, don’t worry if you don’t understand the syntax and reference to specific classes such as TextView. This will be covered at length in subsequent modules.

Eclipse shows an ‘x’ symbol on line #11 which means that this particular line is causing a compilation error. Click on the ‘x’ symbol and choose the ‘Import TextView’ option.

Adding Logic to Java  Project4

The problem was that we used the TextView class without importing it. We’ll use this Eclipse feature in future modules in order to resolve missing imports compilation errors.

Once you save the file (Ctrl + S), the ‘x’ symbol will disappear – we’re now all set to run our ‘Hello World’ application.

Running Hello World Android Project

To run the ‘Hello World’ application, select the Run -> Run option in the Eclipse menu.

Running Android Project

This launches the Android simulator. It takes a while when you do it for the first time.

Running Android Project1

In the next module, we’ll dissect the Hello World application and understand the various pieces involved in building an Android application.

PrevMain