Android Tutorial -Coding a basic application

Android Tutorial -Coding a basic application

This section provides a whirlwind tour of building an Android application. The example application is about as simple as you can imagine: a modified “Hello Android” application. You’ll add a minor modification to make the screen background color all white so you can use the phone as a flashlight. Not very original, but it will be useful as an example. Download the full source code.

To create an application in Eclipse, select File > New > Android project, which starts the New Android Project wizard.
Figure 5. New Android project wizard
The new Android project wizard

Next, you create a simple application with a single activity, along with a UI layout stored in main.xml. The layout contains a text element you’re going to modify to say Android FlashLight. The simple layout is shown below.
Listing 1. Flashlight layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:text="@string/hello" android:textColor="@color/all_black" 

Create a couple of color resources in strings.xml.
Listing 2. Color in strings.xml

<?xml version="1.0" encoding="utf-8"?>
    <string name="hello">Android FlashLight</string>
    <string name="app_name">FlashLight</string>
    <color name="all_white">#FFFFFF</color>
    <color name="all_black">#000000</color>

The main screen layout has a background color defined as


. In the strings.xml file, you see that


is defined as an RGB triplet value of #FFFFFF, or all white.

The layout contains a single


, which is really just a piece of static text; it is not editable. The text is set to be black and is centered horizontally with the



The application has a Java source file called, as shown below.
Listing 3.

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

The code is boiler-plate directly from the New Project wizard:

This article of Android Tutorial to Learn Android Development has been

take from IBM please click the link to read the entire article

learn android programming

This entry was posted in Android Tutorials and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Security Code: