Hello World in Android

After installing the SDK and eclipse extension, next step is to create a our HelloWorld code, isn’t it?

That is very simple

Start a new Android Project in Eclipse

Give necessary parameters. Please see the explanations below (Credit: developer.android.com)

Here is a description of each field:

Project Name
This is the Eclipse Project name — the name of the directory that will contain the project files.

Application Name
This is the human-readable title for your application — the name that will appear on the Android device.

Package Name
This is the package namespace (following the same rules as for packages in the Java programming language) that you want all your source code to reside under. This also sets the package name under which the stub Activity will be generated.

Your package name must be unique across all packages installed on the Android system; for this reason, it’s very important to use a standard domain-style package for your applications. The example above uses the “com.example” namespace, which is a namespace reserved for example documentation — when you develop your own applications, you should use a namespace that’s appropriate to your organization or entity.

Create Activity
This is the name for the class stub that will be generated by the plugin. This will be a subclass of Android’s Activity class. An Activity is simply a class that can run and do work. It can create a UI if it chooses, but it doesn’t need to. As the checkbox suggests, this is optional, but an Activity is almost always used as the basis for an application.

Min SDK Version
This value specifies the minimum API Level required by your application. If the API Level entered here matches the API Level provided by one of the available targets, then that Build Target will be automatically selected (in this case, entering “2” as the API Level will select the Android 1.1 target). With each new version of the Android system image and Android SDK, there have likely been additions or changes made to the APIs. When this occurs, a new API Level is assigned to the system image to regulate which applications are allowed to be run. If an application requires an API Level that is higher than the level supported by the device, then the application will not be installed.

Once you are done with the wizard, eclipse will give you one activity class.

We edit the class so that Android world will say our name 🙂

package org.grassfield.android;

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

public class HelloWorld extends Activity {
/** Called by the android when the activity is first created.
* Do the initialisations here.*/
public void onCreate(Bundle savedInstanceState) {
* An Android user interface is composed of hierarchies of objects called Views.
* A View is a drawable object used as an element in your UI layout,
* such as a button, image, or (in this case) a text label.
* Each of these objects is a subclass of the View class and
* the subclass that handles text is TextView.
TextView textView = new TextView(this);
textView.setText("Grassfield Welcomes!");

The project folder structure is like this

Once you are done with code editing, Build your project once.

Run the project as a Android Application

You will see your phone running your application now! WOW 🙂

now in landscape!!

Long live java, unix, android!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s