Thursday 12 September 2013

Hello World Example

In this tutorial we will learn to Develop our first Android Application and also we will check that our Eclipse Setup is working or not.
You Dont need to code for this example.
Just follow the steps.
Start your Eclipse First.
We have created our AVD or Emulator and if dont created your AVD then create it first using my previous tutorial.
Now go to your Menu Bar of Eclipse
Menu Bar--> File --> New --> Android Application Project.
Follow Below Image.


New Window Will Present to screen.



New Android Application.
You will asked to add Application name. You may named it whatever you want but start with uppercase letter.
Here we leave it as HelloWorld.
Then specify your project name whatever it can be. Here HelloWorld.
Package  Name : You can specify your Package Name which is seperated by .(DOT).
You may choose Minimum SDK required for your Application.
If you choose 2.2 then application will run on all of the above SDK versions but not on below SDK versions.
you may choose your target SDK you want to Develop your application for.
And you can choose the themes from combobox for your Application.

Now Press Next Button.

Now you have to Configure your Project.


Your Window Will look like this.

Now Press Next.

Now You Have To Configure Your Launch Icon.


You can select Foreground and can browse your Desktop to select image as launcher Icon.



Now Press Next.
Create your activity.
you may leave it as Blank Activity.


Click Next.
Now Name your Activity And Layout.


Now Press Finish.
Eclipse Will load your configuration for application.
Now your project or applications window will occure.


window is showing graphical layout and its right side its XML file.

XML code will Look Like 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=".ArshadActivity" >

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

</RelativeLayout>



No need to change your XML.

Now Open Your Activities Java file.


Open Your MainActivity.Java file.
java file's window will look like below


Code Will be like.

package arshad.helloword;

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

public class ArshadActivity extends Activity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.arshad, menu);
        return true;
    }

}


No  need to change it. but for further development you need yo code at your java file. so i just shown you java file.


Now Run Your Application .
Right Click On Your Project then select "Run as " Option.
then select "Android Application".
you have created AVD so Eclipse will run Your Project or Applicarion.


Your Emulator or AVD will launch and will install your application for Hello world.
AVD Will start to Run your Activity and your HelloWorld Will be show on your AVD Like Below.
So this is your Hello World Application.
and if your application runs then we can say our eclipse set up is working.


All The Best :)

No comments:

Post a Comment