Android First Program eclipse- getting started

Android apps are written in Java, and use XML extensively. I shall assume that you have basic knowledge of Java programming and XML.
Step 0: Read - Read "Hello, world" tutorial at http://developer.android.com/resources/tutorials/hello-world.html.
Step 1: Create a Android Virtual Device (AVD) - AVDs are emulators that allow you to test your application without the physical device. You can create AVDs for different android platforms (e.g., Android 2.3 for phone, Android 3.2 for tablet) and configurations (e.g., screen sizes and orientations, having SD card and its capacity).
  1. Launch Eclipse. From "Window" menu ⇒ "Preferences" ⇒ "Android" ⇒ In "SDK Location", enter your Android SDK installed directory (e.g., "d:\myproject\android").
  2. From "Window" menu ⇒ "AVD Manager" ⇒ "Virtual Devices" ⇒ "New" ⇒ "Create New Android Virtual Device dialog appears.
  3. In "Name" field, enter a name such as "my_avd23". Choose a target platform, such as Android 2.3 for testing on smart phone ⇒ "Create AVD".
  4. Repeat the steps to create another AVD called "my_avd32" with target platform of Android 3.2 for testing on tablet.
Step 2: Create a new Android Project
  1. From Eclipse's "File" menu ⇒ "New" ⇒ "Project..." ⇒ "Android Project" ⇒ "Next" ⇒ The "New Android Project" dialog appears.
  2. In "Project Name", enter "Hello" (this is the Eclipse's project name) ⇒ "Next" ⇒ In "Build Target", select your target device ("Android 2.x" for phone; or "Android 3.x" for pad) ⇒ In "Application Name", enter a name that will show up with the program icon, e.g., "Hello". In "Package Name", enter "com.mytest" (this is the Java package name). In "Create Activity", enter "HelloAndroid" (this is the main Java class name for the android application) ⇒ "Finish". Ignore the warning/error messages, if any.
    (You should set the target at the lowest possible level that supports your application requirements. This is because your codes will be able to run on the later versions, but not vice versa. Setting to lowest level will maximize the number of devices that your application can run on. These examples should be supported in Android 2.0, or even any version above 1.6.)
Step 3: First Android Program to say "Hello, world"
In Eclipse's "Package Explorer" (left-most panel), expand the "Hello" project node ⇒ "src" ⇒ package "com.mytest" ⇒ Open "HelloAndroid.java" ⇒ Modify the codes as follows:
package com.mytest;
   
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
   
public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView textView = new TextView(this); // Construct a TextView UI
        textView.setText("Hello, world!");      // Set text for TextView
        setContentView(textView);               // This Activity sets content to the TextView
    }
}
Step 4: Run the Android Program - Run the application by selecting the "Run" menu ⇒ "Run" ⇒ "Android Application". Be patient! It takes quite sometimes to fire up the emulator. Watch the Eclipse's console for messages. Unlock the Android device, by holding and sliding the unlock bar to the right (or left). You shall see "Hello, world!" displayed on the emulator. (If your program is not launched automatically, try launching it from the application launcher manually, after the emulator is up.)


Showing Hello World : Android First Application



























Removal of Errors : You may encounter the following errors based on your configuration.
[ PANIC: Could not open: C:\Users\gTiwari\.android/avd/MyAndAVD.ini ] and
[ invalid command-line parameter: Files ]


The tutorial on removing these errors is here : http://ganeshtiwaridotcomdotnp.blogspot.com/2011/08/first-error-free-android-hello-world.html

No comments:

Post a Comment

Your Comment and Question will help to make this blog better...