Sie sind auf Seite 1von 7

Hello World!

By Andy, on January 4th, 2011


In most program languages, the first application may be the Hello World. Fortunately, Android
SDK is so-called a build-in Hello World software. That mean when you create a new project and
just build and run, it will display Hello Word.
Lets try the first application step by step. First, start Eclipse which is already plug-in Android
SDK. Then go to Menu / File / New / Project to create a new project

New Project Menu
It will open a New Project window and select Android / Android Project and click Next
button.

New Project
In the New Android Project window, type like below. and click Finish button.
Project Name (Package name on Eclipse): HelloWorld
Build Target (Just same as my device platform): Android 2.1-update1
Application name (App name on device): Hello World
Package name (Java package name arbitrarily): edu.android.helloworld
It will be placed in HelloWorld / src / edu.android.helloworld
Create Activity (Basic class name arbitrarily): HelloWorld
It will be placed in HelloWorld / src / edu.android.helloworld / HelloWorld.java
Min SDK Version (Same as Build Target API Level): 7

New Android Project
After creating a new Android project, you better check the following three files.
- HelloWorld.java (located in HelloWorld / src / edu.android.helloworld / )
- AndroidManifest.xml (located in HelloWorld / )
- main.xml (located in HelloWorld / res / layout / )

HelloWorld.java

AndroidManifest.xml

main.xml
Without modify anything, just try to run this application.Select HelloWorld.java code and go to
Menu / Run / Run.

Run Menu
Then it will open Run As window and select Android Application and click OK button.

Run As
Finally, an Android emulator is excuted (it took some times) and ask to unlock the screen to
see the result. FYI, you have to already setup the AVD (Android Virtual Device) to see the
emulator.

Android Emulator
After unclock the screen, you can see the Hello World application result screen.

Hello World Application
If you want to change the text such as This is my first Android application. you need to change
like below in HelloWorld.java file.

Updated HelloWorld.java
Save the change, and try to run again with other way by right mouse click on the HelloWorld
package name and select Run As / Android Application.

Right Mouse Click on Package name
Since the emulator loading time is very long, you better not close the emulator. With opened
emulator, you can update code and re-run without problem and not waiting.

Revised Hello World
If you want to run the application on your Android phone, connect your phone using USB cable
and try to run the application. Then Android Device Chooser window is open automatically.

Android Device Chooser
Select your phone and click OK. Then you can see the same result in your phone with new
application icon created named Hello World.

Device Screen Capture

Das könnte Ihnen auch gefallen