Android Hello World App Tutorial – Your Step by Step Guide

I had a previous post “Getting Started with Google Android Development“ where we installed our development environment. Please refer to that first if you’re not yet done with it. In this post, we are going to do a program that will simply put a “Hello Android!” text on the screen of our android device. This is just a simple “Hello World!” program – just an Android version. Haha!

Home>Android Android Hello World App Tutorial – Your Step by Step Guide

Hello there! :)

Step 1: We have to Install at least one Android platform for it is required to run an android application. To do that, we have to follow the simple steps on this link: Installing an Android platform

Step 2: From eclipse, select File > New > Project (Not Java Project). New project wizard will pop up. On the list, select Android Folder > Android Project > Next

Step 3: You are now in the New Android Project Dialog Box. Supply the following:

  1. Project Name: HelloAndroid.
  2.           This is the name of the directory that will contain the project files

  3. Application Name: Hello Android App
  4.           This is the name that will appear on the Android device

  5. Package Name: com.example.helloandroid
  6.           This is the package namespace that you want all your source code to reside under. It must be unique across all packages installed on the Android system

  7. Create Activity: HelloAndroid
  8.           This is the name for the class stub that will be generated by the plugin

  9. Min SDK Version: 4
  10.           This value specifies the minimum API Level required by your application. Since I am using Android 1.6 platform for now, we’ll enter “4″.

Step 4: Click Finish

You may now browse HelloAndroid.java and see the code by double clicking it.

helloandroid

Step 5: Browse the code. Inside HelloWorld.java file is the auto generated code:

package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;

public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

Change that to these codes. The highlighted codes were added. tv.setText(“Hello, Android”); Displays the text to the application’s UI.

package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HelloAndroid 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, Android");
       setContentView(tv);
   }
}

Step 6: Run the application.

To run the application, for now, we will export it as .apk file. APK file is used for distributing and installing bundled components onto the Android operating system.

exportandroid

After clicking export, an export dialog box will appear, we have to choose Android Folder > Export Android Application > Next > Project: HelloAndroid > Next Button

We are now in the Keystore selection dialog, since this is our first application we have to select Create new keystore radio button. For now, we will supply the following information in the form

Location: C:JM_FILESJAVAKEYSHelloAndroidKey
Password: asdfasdf
Confirm: asdfasdf

Then Click the Next Button to proceed with the Key Creation. We’re gonna supply the following information:

Alias: HelloAndroidAlias
Password: asdfasdf
Confirm: asdfasdf
Validity: 25
First and Last Name: Your Name
Organizational Unit: IT
Organization: IT Org
City or Locality: Antipolo
State or Province: Rizal
Country Code (XX): 18700

Then Click the Next Button

For the destination of APK file, we’ll have: C:JM_FILESJAVAAPKHelloAndroid.apk

Hit the Finish Button

We will now copy the HelloAndroid.apk file to our Android device > Click to install.

You should see “Hello Android!” text when you run the application so you know that our exercise works!

If you’re gonna proceed with total android applications development, you must use the Android Debug Bridge. It will save you a lot of time in debugging. To use that, I got the following useful resources:

http://developer.android.com/guide/developing/tools/adb.html
http://www.youtube.com/watch?v=BKW9xUPJMEM
http://www.androidtablets.net/forum/android-tablet-hacking/426-resource-how-use-adb-android-debug-bridge.html

Other resources:
http://developer.android.com/resources/tutorials/hello-world.html
http://simple.wikipedia.org/wiki/Hello_world_program
That’s it! I hope I helped you with your first android application. :)