Android Hello World Example

By | September 3, 2012
As a beginner to android everybody wants to write there first hello world application to make there hand wet and also to make ensure does development environment is set properly and also to check does the program executes correctly .

In this tutorial, we will see how to create a simple “hello world” Android project in Eclipse IDE + ADT plugin, and run it with Android Virtual Device (AVD).

So Before Developing your first android Hello world application , make sure you have setup development environment if not then visit the our following tutorials .



Development Environment Setup For Android

  1.    Install Android SDK and ADT Plugin for eclipse .
  2.    Create Android Virtual Device (AVD) .

Tools and Technology used in this tutorial

  1. JDK 1.7 
  2. Eclipse 4.2  ( Juno ) .
  3. Android SDK .

In eclipse menu bar go to File –>new –>Android Application Project


First Android Hello World example

Select the Android Application Project and click next


Enter the Application Details

 

Application Name  :   HelloWorldApp
Project Name  :  HelloWorldApp
Package Name  :  com.pavan.helloworldapp

Minimum Reqiured SDK  : Android 2.2 ( API level 8 )
Target SDk   :   Android 4.2 ( API level 17 )
Compile with :  Android 4.2 ( API level 17 )
Theme :  Holo light with Dark Acton Bar

Configure the Launcher Icon

you can add your own custom icon and edit it by setting it’s shape to either square or circle and also you can add padding to it .

First Android Hello World example
First Android Hello World example

                                              Enter the activity name and layout name and click finish 


Project Structure

 Eclipse will create all the necessary Android project files and configuration.
First Android Hello World example

XML Layout

Create  activity_main.xml  file and  add textview  with a string value hello world 
file :-activity_main.xml
< LinearLayout
      xmlns:android=”http://schemas.android.com/apk/res/android”
      xmlns:tools=”http://schemas.android.com/tools”
      android:layout_width=”match_parent
      android:layout_height=”match_parent
      android:padding=”20dp”
      tools:context=”.MainActivity” >
  
    < Textview       
               android:layout_width=”wrap_content”
               android:layout_height=”wrap_content”
               android:text=”@string/hello_world”
               android:textSize=”30dp” >

 < /LinearLayout >

Activity

Create a MainActivity.class and extend it to activity class and override the onCreate() method of activity class and set the content of the actvity with the above defined xml file by calling setContentView() method and passing xml file name as a parameter to it

                                    setContentView(activity_main); 

file :- MainActivity.java

package com.pavan.helloworldapp;

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

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
     }

}

RUN

click Run icon in eclipse toolbar or press( Ctrl+F11 ) to Run application in emulator .

 

First Android Hello World example