Android hello world example

In this tutorial, we show you how to create a simple “hello world” Android project in Eclipse IDE + ADT plugin, and run it with Android Virtual Device (AVD). The Eclipse ADT plugin provided easy Android project creation and management, components drag and drop, auto-complete and many useful features to speed up your Android development cycles.

Summary steps to develop an Android application :

  1. Install Android SDK
  2. Install ADT Eclipse plugin
  3. Create an Android Virtual Device (AVD)
  4. Create Android Project with Eclipse (Wizard)
  5. Code it…
  6. Start it in Android Virtual Device (AVD)

Tools used in this tutorial :

  1. JDK 1.6
  2. Eclipse IDE 3.7 , Indigo
  3. Android SDK

1. Install Android SDK

Visit this Android SDK page, choose which platform and install it.

In Android SDK installed folder, run “Android SDK manager”, choose what Android version you want to develop.

android sdk manager

2. Install ADT Eclipse plugin

To integrate Android SDK with Eclipse IDE, you need to install Eclipse ADT plugin. Refer to this official guide – “Installing the ADT Plugin“.

In Eclipse IDE, select “Help” -> Install New Software…”, and put below URL :


https://dl-ssl.google.com/android/eclipse/
android ADT plugin
Note
In my case, above ADT plugin is taking years to download, no idea why. If you are facing the similar problem, just download and install the ADT plugin manually, refer to this ADT plugin troubleshooting guide.

3. Create an Android Virtual Device (AVD)

In Eclipse, you can access the “Android Virtual Device (AVD)” in Eclipse toolbar. Click “new” to create a AVD.

android avd manager

Later, Eclipse will deploy the application into this AVD.

4. Create Android Project

In Eclipse, select “File -> New -> Project….”, “Android Project”, and input your application detail. Eclipse will create all the necessary Android project files and configuration.

Eclipse new android project wizard
folder structure

5. Hello World

Locate the generated activity file, and modify a bit to output a string “Hello World”.

File : HelloWorldActivity.java


package com.mkyong.android;

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 text = new TextView(this);
        text.setText("Hello World, Android - mkyong.com");
        setContentView(text);
    }
}

6. Demo

Run it as “Android Application“, see output.

hello world output

Press “Home” button (on right hand side), and you will noticed that “HelloWorld” application is deployed successfully on the Android virtual device.

android deployed
Note
This tutorial is more to example driven, not much explanation. For detail and complete explanation, please refer to the official Android developer hello world tutorial.
Firewall…
In my computer, the COMODO firewall is installed and blocked the deploying process, caused the connection between Eclipse ADT and AVD is blocked and failed to deploy. Just make sure your firewall is configured properly, or just turn it off for Android development :)
Debug Android application on real device
Sometime, “Android Virtual Device” is not enough to test some real phone functionalities, like led light, sensor and etc. Then you should refer to this how to debug Android application on real device.

Download Source Code

Download it – Android-HelloWorld.zip (15 KB)

References

  1. Android Developers

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

Leave a Reply

avatar
newest oldest most voted
Shiv Ganesh
Guest
Shiv Ganesh

I was just venturing through your post and found that these are a bit old and outdated. Are you having any plans to update them so that we can use Android Studio and get started. I have really liked your site from a long time and thought of suggesting.

Trey
Guest
Trey

It is not Java it is different.

Guest
Guest
Guest

hadbfhbfhs!@#$#%#%#$%#$%

Philip Jeffrey Trowe
Guest
Philip Jeffrey Trowe

Check out my blog. It provides a video to show you how to create your first Android Hello World app.

http://androidprogrammeringcorner.blogspot.com/2015/02/pak-longs-programming-corner-for.html

Best regards,

Philip

Prem Pratick Kumar
Guest
Prem Pratick Kumar

Please post for in this sections. Its really helpful.

Cashlele
Guest
Cashlele

Hey mkyong, I m new in android application development.So this tutorial really helped to get all basic things .Thanks man..!!!
http://www.cashlele.com

likhith
Guest
likhith

hi Mkyong…. I am new to android …. ia have serious problem when i creatyed my first application… the virtual device which i created fail to load and emulator launch is failed for simple Hello world applciation… so can u support to rectify the problem

Tan Nguyen
Guest
Tan Nguyen
mukesh jat
Guest
mukesh jat

not sufficient info :(
http://www.india.dj

Ian Kim
Guest
Ian Kim

thanks sir

Android Guru
Guest
Android Guru

Good start for beginners!
Do visit http://android.programmerguru.com for Android tutorials.

Nithin kumar
Guest
Nithin kumar

i am not able to install the adt packages to eclipse juno in windows 7

Dinesh
Guest
Dinesh

Thank you !! The tutorial was very simple for beginners..Thanks again..

Anuvab Ghosh
Guest
Anuvab Ghosh

Thank u Sir…This is helpful to setup and to complete the first Apps in Android.

mtive
Guest
mtive

sir this is very informative i want to learn that how to earn with android development plz guide
i found a very use full learn4do . com

SATHVIK
Guest
SATHVIK

Need temperature converting program

plss need it urjent!!!

Thanks in advance

FROM ALIET

DHARANI
Guest
DHARANI

thanks :):)

Code Nirvana
Guest
Code Nirvana

Sir!
I don’t know android programming currently but completed the first step and installed it successfully.
Have a look a step by step installation process: http://www.codenirvana.in/2013/05/start-developing-for-android-with.html

matao
Guest
matao

android

Sunny
Guest
Sunny

Great start with android.waiting for more on Android tuts from you sir.

regards,
Sunny

Sunny
Guest
Sunny

Great start with android.waiting for more on Android tuts from you sir.
http://websnube.com/

regards,
Sunny

Nitin
Guest
Nitin

Hi,

I am completely new in this and I followed all the above steps but for me under new project –> Android, ‘android project’ is not present. Could you elaborate a little more on each step. How to add AVT (MyAndroid). I have eclipse indigo release 2 and Android 4.2.2. Help me in executing the hello world atleast.

Arun
Guest
Arun

I’ve built a very small game app that has no more than two activities and so two java classes. But the apk that I get out of it is abt 800KB. But I see apps on store that are even lesser than 400 KB. And those apps are definitely no of just two java classes. For example a MP3 cutter is of 400KB. Even Opera browser is of just 804KBs. What do they do to reduce the size of the apk? Do I have any unwanted files/images in my eclipse project that have been created by default?

pavan
Guest
pavan

very nice tutorial you can also check this one
http://pavanhd.blogspot.in/2012/09/android-hello-world-example.html

Meghna
Guest
Meghna

Thanks for the clean explanation.. This website http://www.compiletimeerror.com/2012/12/creating-first-androidapplication-in.html also addresses something similar.. Have a look, may help..

anu
Guest
anu

good tutorial

Android Guru
Guest
Android Guru

How to check whether Wi-Fi internet access is active or not in a device. Take a look at the post:
http://android.programmerguru.com/android-check-wifi-internet-connection/

kanimozhi
Guest
kanimozhi

thank

Ashish
Guest
Ashish

Hello Friends

If u want run emulator using command prompt then go to c:\program files\android\android_sdk\platform_tools

and keep your apk on platform tools

and issue command on cmd : cd c:\prorgram files\android\android_sdk\platform_tools

then run adb install filename.apk

if u want run directly on your mobile then issue command:

adb -d install filename.apk

godel
Guest
godel

hai mkyong…..

i’m using eclipse juno
it’s AVD emulator not working. why?

it’s error code is
PANIC : not open android
(my avd create with name android)

please help me
contact me by email
thanks

dev
Guest
dev