Android : Your First Dream Application Hello World

android-for-wallpaper-8

1. The “Eclipse Classic” version is recommended. Otherwise, a Java or RCP version of Eclipse is  recommended.

2. Install the SDK starter package from the table above.

  • Windows android-sdk_r15-windows.zip
  • installer_r15-windows.exe (Recommended)

3. Install the ADT Plugin for Eclipse (if you’ll be developing in Eclipse).

4. Add Android platforms and other components to your SDK.

After installing ADT and SDK.We can launch the Android SDK and AVD Manager in one of the following ways:

  • From within Eclipse, select Window > Android SDK and AVD Manager.
  • On Windows, double-click the SDK Manager.exe file at the root of the Android SDK directory.
  • On Mac or Linux, open a terminal and navigate to the tools/ directory in the Android SDK, then execute: android
  • In the right panel, expand the Android Repository list to display the components available for installation.
  • Select at least one platform to install, and click Install Selected. If you aren’t sure which platform to install, use the latest version.
  • To download components, use the graphical UI of the Android SDK and AVD Manager to browse the SDK repository and select new or updated components. The Android SDK and AVD Manager installs the selected components in your SDK environment. 

Create an AVD

Here you will run your application in the Android Emulator. Before you  launch the emulator, you must create an Android Virtual Device (AVD). An AVD defines the system image and device settings used by the emulator.

To create an AVD:

  1. In Eclipse, select Window > Android SDK and AVD Manager.
  2. Select Virtual Devices in the left panel.
  3. Click New…. The Create New AVD dialog appears.
  4. Type the name of the AVD, such as “my_avd”.
  5. Choose a target. The target is the platform (that is, the version of the Android SDK, such as 2.3.3) you want to run on the emulator. Choose the latest platform that you have installed and ignore the rest of the fields.
  6. Click Create AVD.

Create a New Android Project

Next  step start the eclipse 

In Eclipse, select File > New > Project….

  1. If the ADT Plugin for Eclipse has been successfully installed, the resulting dialog should have a folder labeled “Android” which should contain “Android Project”.
  2. Select “Android Project” and click Next.
  3. Fill in the project details with the following values:
    • Project name: HelloAndroid
    • Build Target: Select a platform version that is equal to or lower than the target you chose for your AVD.
    • Application name: Hello, Android
    • Package name: com.example.helloandroid (or your own private namespace)
    • Create Activity: HelloAndroid

    Click Finish.

    Your Android project is now ready. It should be visible in the Package Explorer on the left. Open the HelloAndroid.java file, located inside HelloAndroid > src > com.example.helloandroid). It should look like this:


package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

Ready for  UI?

Modify the above code

 
package com.example.helloandroid;

 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 tv = new TextView(this);
       tv.setText("Hello, Android");
        setContentView(tv);
    }
 }

Run the Application

The Eclipse plugin makes it easy to run your applications:

  1. Select Run > Run.
  2. Select “Android Application”.

The Eclipse plugin automatically creates a new run configuration for your project and then launches the Android Emulator. Depending on your environment, the Android emulator might take several minutes to boot fully, so please be patient. When the emulator is booted, the Eclipse plugin installs your application and launches the default Activity. You should now see something like this: 

 Happy Coding……
Total Page Visits: 70344 - Today Page Visits: 48

Leave a Reply