Starting a New Project in Eclipse :
Start Eclipse: You should see a screen that looks similar to the one shown in Figure. Now you’re ready to start cooking with Android.
Follow these steps to create your first Android application project:
1. In Eclipse, choose File ➪New ➪Other ➪ Select Android Application Project. The New Android App Wizard opens, as shown in Figure.
2. Write Hello Android as the application name.
- 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 appears in the application launcher.
- The Project and Package names should autocomplete for you. The Project Name field is important. The descriptive name 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.
3. In the Package Name box, type com.androidinterview.helloandroid. This is the name of the Java package.
4. Select Target Android 4.4 from the Build SDK drop-down list and API 8: Android 2.2 from the Minimum Required SDK drop-down list, and then click Next.
- The Build SDK drop-down list identifies which application programminginterface (API) you want to develop for this project. Always set the Build Target SDK to the latest version that you’ve tested your app on.
- Setting the Minimum Required SDK version lower than the Build Target SDK means that your app still runs on older devices, all the way down to Android 2.2 in this case.
5. New application configure project dialog box open click on Next.
6.(Optional Configure icon launcher) Create an application icon for your project and click Next.
7. In the Create Activity box, choose BlankActivity and click Next.
The New Blank Activity screen appears, as shown in Figure
9. Enter MainActivity in the Activity Name box.
The New Blank Activity screen defines what the initial activity is called —the entry point to your application. When Android runs your application, this file is the first one to be accessed. A common naming pattern for the first activity in your application is MainActivity.java.
10. Click the Finish button.
You’re done! You should see Eclipse with a single project in the Package Explorer. For the purpose of this book, Package Explorer and Project
Explorer (which is showing in Figure 3-4) are the same thing. Different names; same function.
Setting Up an Emulator :
You’re almost ready to run your application in Eclipse. You have one final thing to set up, and then you get to see all your setup work come to life in the Hello Android application. To see this application in a running state, you need to know how to set up an emulator through the various launch configurations.
You need to create an Android Virtual Device (AVD), also known as an emulator. An AVD is a virtual Android device that looks, acts, walks, and talks (well, maybe not walks and talks) like a physical Android device. AVDs can be configured to run any particular version of Android as long as the SDK for that version is downloaded and installed.
It’s time to get reacquainted with the old standbys Android SDK and AVD Manager. Follow these steps to create your first AVD:
1. Click the icon on the Eclipse toolbar, shown in Figure.
The AVD Manager dialog box opens.
2. Click the New button. The Create New Android Virtual Device (AVD) dialog box opens, as
shown in Figure.
4. In the Target box, select Android 4.4 — API Level 19.
5. In the SD Card section, leave the fields blank.
You have no use for an SD Card in the Hello Android application. You would use the SD Card option if you needed to save data to the SD card. If you want to have an emulator in the future, insert the size of the SD card in megabytes (MB) that you want to have created for you. At that time, an emulated SD Card will be created and dropped in your local file system.
6. Leave the Skin option set to Default (WVGA800) or HVGA.
7. Don’t select new features in the Hardware section.
The Hardware section outlines the hardware features your AVD should emulate. You don’t need extra hardware configuration for the Hello Android application.
8. Click the Create AVD button.
Figure shows the completed AVD Manager dialog box.
9. Close the Android SDK and AVD Manager dialog box.
Creating Launch Configurations :
You’re almost at the point where you can run the application. A run configuration specifies the project to run, the activity to start, and the emulator or device to connect.
When you first run a project as an Android application by choosing Run.Run, the ADT automatically creates a run configuration for you. The Android Application option is visible when you choose Run➪Run. After the run configuration is created, it’s the default run configuration, now used every time you choose Run➪Run.
If want to create a run configuration manually, follow along here. following these steps is simple:
1. Choose Run➪Run Configurations.
The Run Configurations dialog box opens, as shown in Figure. In this dialog box, you can create many types of run configurations. The
left side of the dialog box lists many types of configurations, but focus on these:
- Android Application
- Android JUnit Test
2. Select the Android Application item, and click the New Launch Configuration icon(left top corner).
Or right-click Android Application and choose New from the context
menu. The New Launch Configuration window opens.
3. Type ExampleConfiguration in the Name field.
If you want to start from an existing launch configuration, right-click it, and choose Duplicate from the context menu. Change the name of the run configuration by entering a name in the Name field. You can then change various settings to give the launch configuration a unique configuration.
4. On the Android tab, click the Browse button to select the project you’re creating this launch configuration for.
The Project Selection dialog box opens, as shown in Figure.
5. Select Hello Android and click OK.
The Run Configurations dialog box reopens.
6. On the Android tab, leave the Launch Action option set to Launch Default Activity. In this case, the default activity is MainActivity, which you set up in “Starting a New Project in Eclipse”.
7. On the Target tab, shown in Figure , leave Automatic selected(or select New_AVD).Notice that an AVD is listed in the Select a Preferred Android Virtual Device for Deployment section.
9. Leave the rest of the settings alone, and click the Apply button.
Running the Hello Android App:
Running the application is simple. Upon your instruction, the ADT launchesan emulator with the default launch configuration you build earlier in this topic. Starting your application is as simple as choosing Run.Run orpressing Ctrl+F11. Either action launches the application in an emulator using the default launch configuration — in this case, ExampleConfiguration.
The ADT compiles your application and then deploys it to the emulator. If you didn’t create a launch configuration, you see the Run As dialog box, shown in Figure . Choose Android Application, and a launch configuration is created for you.
Immediately thereafter, the ADT starts the Hello Android application for you. You see an empty screen containing the words Hello world!, as shown in Figure.
Note : This example (Project) is developed in Eclipse Version Kepler, tested on Android 4.4.2 (KitKat Version) and SDK build-tools 22.6.3