Here we will learn how to create a simple "Hello World" Android project in Eclipse IDE using ADT plugin and run it with Android Virtual Device.
The required tools for Android development are :
The required tools for Android development are :
- JDK 1.6
- Eclipse IDE
- Android SDK
To develop the Android application, we will follow the below steps :
- Download and install the Android SDK
- Download and install the ADT Eclipse plugin
- Create an Android Virtual Device(ADT)
- Create an Android Project in Eclipse
- Run the application in Android Virtual Device
Download and install the Android SDK
Go to the Android SDK Page and download the appropriate version for your platform. You can download the ADT(Android Development Tool) bundle, in which you will find both Eclipse and Android SDK. After installation on running the sdkmanager.exe following window will appear.
Download and install the ADT Eclipse plugin
In this step we are going to integrate the Android SDK with Eclipse by using ADT plugin.
Open Eclipse and select Help-->Install New Software. Here we will get a window with a edit field to put the following URL and click Add.
https://dl-ssl.google.com/android/eclipse
Create an Android Virtual Device(AVD)
After the installation of the ADT plugin, restart the Eclipse. After restarting the Eclipse, you will get two Android Development icon on the Eclipse Toolbar.
These icon launches the SDK Manager and AVD Manager respectively. On launching the AVD Manager, a window will appear.
Click on NEW to create the new AVD.
Create the Android Project in Eclipse
- To create the new project go to File-->New-->other-->Android-->Android Application Project.(OR ctrl+n--->Android-->Android Application Project.)
Enter the Application name, Project name and Package name. Choose a Build SDK that suits your test devices and favored emulator configuration.
Here, the package name should not begin with any of the following values(not allowed in Google Play ):
- com.android
- com.google
- android
- com.example
- com.test
Click Next, a window will appear for configuring launcher icon. You can always change the launcher icon later.
Click Next, another window for creating Activity will appear. Here select Blank Activity.
Click Next, again new window for specify Activity details
On click on Finish, you will get the project in Project Explorer in Eclipse. Here is the structure of the project
src
This contains the .java source files for your project. By default, it includes an MainActivity.java source file having an activity class that runs when your app is launched using the app icon.
gen
This contains the .R file, a compiler-generated file that references all the resources found in your project. You should not modify this file.
bin
This contains the .APK(Android package file) built by the ADT during the building process and everything else needed to run the an Android application.
res/drawable-hdpi
This contains drawable objects that designed for high-density screen
res/layout
This contains the file that define app's user interface.
res/values
This contains the other various XML files contains a collection of resources, such as strings and colors definitions.
AndroidManifest.xml
This is the manifest file which describes the fundamental characteristics of the app and defines each of its components.
The Main Activity File
The main activity code is in a java file MainActivity.java. This is the actual application file which ultimately get converted to Dalvik executable and runs application.
package com.company.basichelloworld;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
This onCreat() method is called first time when activity is started and application is not loaded. But for subsequent start of the activity, the onCreat() method of application will not bne called.
setContentView() load the UI for the respective activity. R.layout.activity_main refers the activity_main.xml located in res/layout folder.










No comments:
Post a Comment