How to write a simple Android application?

In my previous article I have explained about how to set up the android environment. This article shows you how you can create a simple Android Application using eclipse. This example assumes that you have already set up the android environment and ready for the development. If you have any questions, please post it in the comments section.

Step1: Open the Eclipse IDE and create an Android App

Select  File->New->Project->Android->Android Project->Next Refer the below screen for more details about the dialog box.

Enter the Following Details in the screen:

  1. Project name: MyFirstApp
  2. Application name: Android App
  3. Package name:
  4. Create Activity: helloWorld
  5. Min SDK version: 8(Min SDK version should be same as the API level)
  6. Build Target: Android 2.2

After filling up the above details, click on “Finish” button.

Android Project Structure

Now the project MyFristApp is created in your workspace. The project Structure is as below.


The Activity helloWorld that you have just created is as below.

import android.os.Bundle;
public class helloWorld extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

main.xml is the automatically created layout file. The content of main.xml is as below.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""

android:text=”@string/hello” here hello contains “Hello World, helloWorld!” string that gets displayed as output. You can store any string in the Textview to get the output of your choice. You can add any number of views to your xml.

Step2: Register the Activity in AndroidManifest.xml

The Default Activity will be automatically registered. The manifest file is as below.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".helloWorld"
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
    <uses-sdk android:minSdkVersion="8" />

Step3: Run the android application

Create the Android Virtual Device to run your app. Select the project Files that you need to run->click on the below highlighted symbol from the toolbar of eclipse IDE.


In the Run as window select Android Application and click OK.  Now the Eclipse installs your app in the AVD.


Step4: Getting the desired Output

strings.xml that gets created automatically is as below:

<?xml version="1.0" encoding="utf-8"?>
    <string name="hello">Hello World, helloWorld!</string>
    <string name="app_name">Android App</string>

Change the contents of strings.xml to alter the output go to  res folder in your project structure->values->open strings.xml->click on the “hello” string. Let us now change the contents of  “hello” string to “Hi Welcome to My World!” The contents of new strings.xml is as below.

<?xml version="1.0" encoding="utf-8"?>
    <string name="hello">Hi Welcome to My World!</string>
    <string name="app_name">Android App</string>

Run the Project as in Step3. The new output is as below


Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!