Android Overview Tutorial: Hello World!
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
Name the project ‘Hello World’ and leave all other settings as default.
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.
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.
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.
Alternatively, click on the AVD Manager in the Eclipse toolbar as shown below.
Click on ‘New’, choose an appropriate AVD name and target Android version and then click on the ‘Create AVD’ button.
The new AVD would then show up in the AVD Manager list as shown below.
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.
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’.
This would turn on the line numbers as shown below.
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.
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.
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.
This launches the Android simulator. It takes a while when you do it for the first time.
In the next module, we’ll dissect the Hello World application and understand the various pieces involved in building an Android application.