Step 02: Hello World App (Java)
- Connect your cell phone (HTC Desire S) to your computer using a USB cable.
- On your cell phone go to Setting>Application>Development and enable USB debugging.
- Start Eclipse by double clicking its icon on your desktop.
- From the "Window" menu, select "Open Perspective > Other..."
- Select DDMS and click OK.
- Check if your cellphone is listed under the "Devices" view and if the logs are being shown under the "LogCat" view. (In Eclipse, various tabbed panes are called "views")
- Go back to the "Java" perspective by clicking on the "Java" button on the top right corner within Eclipse.
- Select "New > Project..." from "File" menu.
- Select "Android Project" listed under "Android" folder and click "Next >".
- Enter details as follows:
- Project Name: 01HelloWorld
- Check "Android 2.3.3" as the Build Target
- Application Name: HelloWorld
- Package Name: com.lithiumhead.android.HelloWorld
- Check "Create Activity" and enter the name as: HelloWorldActivity
- Leave everything else on default
- Click "Finish". A new package will appear under the "Package Explorer".
- Navigate to "HelloWorldActivity.java" listed under "01HelloWorld > src > com.lithiumhead.android.HelloWorld" in the Package Explorer and double click to open it's source code.
- Replace the contents of "HelloWorldActivity.java" with:
- package com.lithiumhead.android.HelloWorld;
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.TextView;
- public class HelloWorldActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- TextView tv = new TextView(this);
- tv.setText("Hello World!!");
- setContentView(tv);
- }
- }
- Save HelloWorldActivity.java by pressing "Ctrl+S".
- Wait for the package to be built automatically. Progress indicator will appear on the bottom right within Eclipse along side the message "Building Workspace".
- Right click "01HelloWorld" under "Package Explorer" and select "Run As > 1 Android Application".
- Unlock your cellphone by clicking the "Power" button on the top side and then sliding your finger over the screen.
- After the screen unlocks, you will see the HelloWorld App running on you phone.
- You can observe the installation messages under the "Console" view within Eclipse.
- To uninstall the "HelloWorld" App, on you PC start cmd.exe and issue the command "adb uninstall com.lithiumhead.android.HelloWorld".
References: