Starting a New Project in Eclipse
First things first: You need to start Eclipse. After it’s started, Now you’re ready to start cooking with Android app development course.
Remember setting up your development environment in the previous chapter? I’m sure you do! In that chapter, you set up all the tools and frameworks necessary to develop Android applications, and in the process of doing so, the Eclipse Android Development Tools (ADT) plug-in was installed. The ADT plug-in gives you the power to generate new Android applications directly from within the Eclipse File menu. That’s exactly what you’re about to do; I think you’re ready to create your first Android Application project. Follow these steps:
1. In Eclipse, choose File➪New➪Project.
The New Project/Select a Wizard dialog box opens
2. From the New Project/Select a Wizard dialog box, expand the Android item by clicking the Android folder.
3. After the Android folder is expanded, click the Android Project and then click the Next button
The New Android Project dialog box appears, as shown in Figure 3-3.
4. In the Project Name field, type Hello Android.
The Project Name field is very important, the descriptive name that you provide identifies your project in the Eclipse workspace. After your project is created, a folder in the workspace is named with the project name you define here.
5. In the Contents pane, leave the default radio button Create New Project in Workspace and the checkbox Use Default Location selected.
These defaults are selected automatically when a new project is created. The Contents panel identifies where the contents of your Eclipse projects are going to be stored in the file system. The contents are the source files that make up your Android project.
When you set up Eclipse in Chapter 2, the Eclipse system asked you to set your default workspace. The workspace usually defaults to your
home directory. A home directory is where the system places files pertinent to you. Figure 3-4 shows my home directory.
If you would rather store your files in a location other than the default workspace location, deselect the Use Default Location check box. This enables the Location text box. Click the Browse button, and select a location where you’d like your files to be stored.
6. In the Build Target section, select Android 2.2.
The Build Target section identifies which application programming interface (API) you want to develop under for this project. By selecting Android 2.2, you have elected to use the Android 2.2 framework. Doing so allows you to develop with the Android 2.2 APIs, which include new features such as the Backup Manager and new speech-recognition APIs. If you selected Android 1.6 as the target, you would not be able to use any features supported by version 2.2 (or 2.1). Only the features in the targeted framework are supported. If you installed other software development kits (SDKs) in Chapter 2, you might have the option of selecting them at this point. If you selected version 1.6, you’d have access only to version 1.6 APIs.
For more information, see the section “Understanding the Build Target and Min SDK Version settings,” later in this chapter.
7. In the Properties section, type Hello Android in the Application Name box.
The application name is the name of the application as it pertains to Android. When the application is installed on the emulator or physical device, this name will appear in the application launcher
8.In the Package Name box, type com.dummies.android.helloandroid.
This is the name of the Java package (see the nearby sidebar “Java package nomenclature”).
9. In the Create Activity box, type MainActivity.
The Create Activity section defines what the initial activity will be called. This is the entry point to your application. When Android runs your application, this is the first file that gets accessed. A common naming pattern for the first activity in your application is MainActivity.java (how creative, right?).
10. In the Min SDK Version box, type 8The Min SDK Version defines the minimum version code of Android that the user must have before he can run your application. Note that this field is not required to create your app.
For more information, see the section “Understanding the Build Target and Min SDK Version settings,”
11. Click the Finish button.
You’re done! You should see Eclipse with a single project in the Package Explorer
DECONSTRUCTING YOUR Project
The Android project generated by Eclipse is a fresh clean project with no compiled binary sources. Sometimes, it takes a second for Eclipse to catch up to how fast you are, so you may notice little oddities about the system. You also need to understand what happens under the hood of Eclipse at a high level; I cover this information in the next sections
Understanding the BUILD Target and Min SDK Version settings
So how does the Build Target setting differ from the Min SDK Version setting?
The build target is the operating system you’re going to write code with. If you choose 2.2, you can write code with all the APIs in version 2.2. If you choose 1.6, you can write code only with the APIs that are in version 1.6. You can’t use the Bluetooth APIs in version 1.6, for example, because they weren’t introduced until version 2.0. If you’re targeting 2.2, you can write with the Bluetooth APIs.
Know which version you want to target before you start writing your Android application. Identify which Android features you need to use to ensure that your app will function as you expect. If you’re positive that you’ re going to need Bluetooth support, you need to target at least version 2.0. If you’re not sure which versions support the features you’re looking for, you can find that information on the platform-specific pages in the SDK section of http:// d.android.com. The Android 2.2 platform page is at http://d.android. com/sdk/android-2.2.html.
Android operating system (OS) versions are backward-compatible. If you target Android version 1.6, for example, your application can run on Android 2.2, 2.1, 2.0, and of course 1.6. The benefit of targeting the 1.6 frameworks is that your application is exposed to a much larger market share. Your app can be installed on 1.6, 2.0, 2.1, and 2.2 devices (and future versions, assuming that no breaking framework changes are introduced in future Android OS releases). Selecting an older version doesn’t come without consequences, however. By targeting an older framework, you’re limiting the functionality that you have access to. By targeting 1.6, for example, you won’t have access to the Bluetooth APIs.
The Min SDK Version setting is the minimum version of Android that the user must be running for the application to run properly on his or her device. This field isn’t required to build an app, but I highly recommend that you fill it in. If you don’t indicate the Min SDK Version, a default value of 1 is used, indicating that your application is compatible with all versions of Android Training
<uses-sdk android:minSdkVersion="integer" android:targetSdkVersion="integer" android:maxSdkVersion="integer" />