Create a New Android Project

After you've created an AVD, the next step is to start a new Android project in Eclipse.

1. From Eclipse, select File > New > Project.

If the ADT Plugin for Eclipse has been successfully installed, the resulting dialog should have a folder labeled "Android" which should contain "Android Project". (After you create one or more Android projects, an entry for "Android XML File" will also be available.)

2. Selected "Android Project" and click Next.

3. Fill in the project details with the following values:

o Project name: HelloAndroid o Application name: Hello, Android o Package name: com.example.helloandroid (or your own private namespace) o Create Activity: HelloAndroid o Min SDK Version: 2

Click Finish.

New Android Project

Creates a new Android Project resource

Project name: | HelloAndroid

Create new project in workspace Create project from existing source I* Use default location

Location: |C:/DocumentsandSettings/smain/workspace/HelloAndroid Browse..,

Build Target

Target Name 1 Vendor 1 Platform 1 API... 1

0 Android 1.1

Android Open Source Project 1.1 2

□ Android 1.5

Android Open Source Project 1.5 3

□ Google APIs

Google Inc, 1.5 3


Application name:

| Hello, Android

Package name:

| com.example.helloandroid

W Create Activity

| HelloAndroid

Min SDK Version:


Here is a description of each field: Project Name

This is the Eclipse Project name — the name of the directory that will contain the project files. Application Name

This is the human-readable title for your application — the name that will appear on the Android device. Package Name

This is the package namespace (following the same rules as for packages in the Java programming language) that you want all your source code to reside under. This also sets the package name under which the stub Activity will be generated.

Your package name must be unique across all packages installed on the Android system; for this reason, it's very important to use a standard domain-style package for your applications. The example above uses the "com.example" namespace, which is a namespace reserved for example documentation — when you develop your own applications, you should use a namespace that's appropriate to your organization or entity.


Create Activity

This is the name for the class stub that will be generated by the plugin. This will be a subclass of Android's Activity class. An Activity is simply a class that can run and do work. It can create a UI if it chooses, but it doesn't need to. As the checkbox suggests, this is optional, but an Activity is almost always used as the basis for an application.

Min SDK Version

This value specifies the minimum API Level required by your application. If the API Level entered here matches the API Level provided by one of the available targets, then that Build Target will be automatically selected (in this case, entering "2" as the API Level will select the Android 1.1 target). With each new version of the Android system image and Android SDK, there have likely been additions or changes made to the APIs. When this occurs, a new API Level is assigned to the system image to regulate which applications are allowed to be run. If an application requires an API Level that is higher than the level supported by the device, then the application will not be installed.

Other fields: The checkbox for "Use default location" allows you to change the location on disk where the project's files will be generated and stored. "Build Target" is the platform target that your application will be compiled against (this should be selected automatically, based on your Min SDK Version).

Notice that the "Build Target" you've selected uses the Android 1.1 platform. This means that your application will be compiled against the Android 1.1 platform library. If you recall, the AVD created above runs on the Android 1.5 platform. These don't have to match; Android applications are forward-compatible, so an application built against the 1.1 platform library will run normally on the 1.5 platform. The reverse is not true.

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

package com.example.helloandroid;

import; 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);

Notice that the class is based on the Activity class. An Activity is a single application entity that is used to perform actions. An application may have many separate activities, but the user interacts with them one at a time. The onCreateP method will be called by the Android system when your Activity starts — it is where you should perform all initialization and UI setup. An activity is not required to have a user interface, but usually will.

Now let's modify some code!

0 0

Post a comment