Searching...
Monday, 24 September 2012

Android Hello world example

14:02

 

Android Hello world example


Softwares Used


Eclipse 3.7
Java 1.6
Android SDK

Steps


1. Download and install Android SDK


( Available in http://developer.android.com/sdk/index.html)

2.Open SDK Manager (Start->Programs->Android SDK Tools) and download Android version


This example used Android 2.1 version
clip_image002

3. Install ADT Eclipse plugin in


Eclipse help menu->Install new software->Add repository with below url
https://dl-ssl.google.com/android/eclipse/

4. Create an Android Virtual Device (AVD)


In Eclipse tool bar we can see AVD Manager/ or Open it from Start->Programs->Android SDK Tools
In this example selected 2.1

clip_image004

5. Create an Android project in Eclipse


Here selected 2.1 version with blank activity (In this example i given activity name as PretechActivity)

clip_image006

6. Please see this project structure and Add TextView Object the Activity class onCreate method.


clip_image008



packagecom.example.pretechandroiddemo;

import android.os.Bundle;
importandroid.app.Activity;
import android.view.Menu;
importandroid.widget.TextView;

public class PretechActivity extends Activity {

       @Override
       public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              TextView view = new TextView(this);
              String s = "Hello world by Pretech Solutions";
              view.setText(s);
              setContentView(view);
       }

       @Override
       public booleanonCreateOptionsMenu(Menu menu) {
              getMenuInflater().inflate(R.menu.activity_pretech, menu);
              return true;
       }
}


7. Run as Android Application


We can see the emulator starting and creating apk file and installing in the console
Note: Some times emulator will take long time to start, please wait for few minutes


[2012-09-25 01:31:46 - PretechAndroidDemo] ------------------------------
[2012-09-25 01:31:46 - PretechAndroidDemo] Android Launch!
[2012-09-25 01:31:46 - PretechAndroidDemo] adb is running normally.
[2012-09-25 01:31:46 - PretechAndroidDemo] Performing com.example.pretechandroiddemo.PretechActivity activity launch
[2012-09-25 01:31:46 - PretechAndroidDemo] Automatic Target Mode: launching new emulator with compatible AVD 'Pretech'
[2012-09-25 01:31:46 - PretechAndroidDemo] Launching a new emulator with Virtual Device 'Pretech'
[2012-09-25 01:31:47 - PretechAndroidDemo] New emulator found: emulator-5554
[2012-09-25 01:31:47 - PretechAndroidDemo] Waiting for HOME ('android.process.acore') to be launched...
[2012-09-25 01:33:15 - PretechAndroidDemo] HOME is up on device 'emulator-5554'
[2012-09-25 01:33:15 - PretechAndroidDemo] Uploading PretechAndroidDemo.apk onto device 'emulator-5554'
[2012-09-25 01:33:16 - PretechAndroidDemo] Installing PretechAndroidDemo.apk...
[2012-09-25 01:34:55 - PretechAndroidDemo] Success!
[2012-09-25 01:34:55 - PretechAndroidDemo] Starting activity


Output



clip_image010
















































0 comments: