Say Hello to Android (Creating First Android App)
×
Home Courses Community Support
Gray Matter

First Step Towards Android: Introduction »

Understanding Activities and Intents »

Hands On With UI Designing In Android (Controls-Views,Widgets and Layouts) »

Updating... »

Say Hello to Android (Creating First Android App)

You need to follow the 3 steps to create the Hello android application.

Create the New Android project

For creating the new android project:

  1. Select File -> New -> Project
  2. Select the android project and click next
     

  3. Fill the all the Details in this dialog box and then click finish
     

Now your android project have been created. You can explore the android project and see the simple program, it looks like this:  

Write the message

To write the message we are using the TextView class. Change the onCreate method as:
 

TextView textview=new TextView(this);
textview.setText("Hello Android!");
setContentView(textview);


Let's see the full code of MainActivity.java file.
 

package com.example.helloandroid;  
import android.os.Bundle;  
import android.app.Activity;  
import android.view.Menu;  
import android.widget.TextView;  
public class MainActivity extends Activity {  
@Override  
protected void onCreate(Bundle savedInstanceState) {  
super.onCreate(savedInstanceState);  
TextView textview=new TextView(this);  
textview.setText("Hello Android! How r u?");  
setContentView(textview);  
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.  
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}


Now you will see your activity_main.xml file as below-

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
????android:paddingLeft="@dimen/activity_horizontal_margin"
????android:paddingRight="@dimen/activity_horizontal_margin"
????android:paddingTop="@dimen/activity_vertical_margin"
????tools:context=".MainActivity" >

????<TextView
????????android:layout_width="wrap_content"
????????android:layout_height="wrap_content"
????????android:text="@string/hello_world" />

</RelativeLayout>


Run the android application

To run the android application: Right click on your project > Run As.. > Android Application

The android emulator might take 2 or 3 minutes to boot. So please have patience. After booting the emulator, the eclipse plugin installs the application and launches the activity.

You will see something like this:
 

 

← Preview

Understanding Components of Application

Next →

Understanding Anatomy/ Internal Details of an Application

NOTES

Our mission is to provide highly effective and quality education via innovative solutions. Geeksdemy look forward to bridge the gap between in-demand technology and academics in order to deliver innovative, easy, interesting and affordable learning across the Globe.

Courses

  • Python
  • Game Development with Unity 3D
  • Arduino
  • PCB & Circuit Designing
  • Robotics and Embedded C
  • 8051/8052 Embedded Systems
  • QuadCopter & UAV
  • MATLAB with Robotics
  • Raspberry Pi
Learn On the Go!
Get the Android App
Get the iOS App