Creating an eclipse project for android. Setting up Eclipse for Android development. Slow launch of the emulator

In this guide, you will learn how to start developing for Android, namely: mobile applications on the Android Eclipse + SDK platform. Today, there are many approaches to developing and creating mobile applications for Android. Complex hardware devices, tablet PCs and various software platforms (Symbian OS, iOS, WebOS, Windows Phone 7...) open up endless space for developers.

So, the list of applications to start developing mobile applications for Android is huge. Which platform should you choose? What programming language should I learn? Which set of applications to choose for project planning? In this guide, you'll learn how to get started developing mobile apps for the Android platform, Google's open mobile OS.

Why Android platform?

Android is an open platform based on the Linux kernel. It is installed on thousands of devices from a wide range of manufacturers. Android provides applications for every type of hardware you can imagine. mobile devices- digital compasses, video cameras, GPS, sensors and much more.

Free Android development tools let you quickly start creating free or almost free applications. When you're ready to show the world your app, you can publish it through the Android Market. Publishing to the Android Market requires a one-time registration fee ($25 at the time of writing) and, unlike App Store Apple (which is very strict about qualifications) makes your app available for download and purchase after quick overview- if the application does not violate the rules and laws.

Here are a few others Android differences SDK that offers you benefits as a developer:

  • The Android SDK is available for Windows, Mac, and Linux, so you don't have to pay for new hardware to write apps.
  • SDK built into Java. If you are familiar with the Java programming language, you are already halfway there.
  • Taking into account the distribution of the application through the Android Market, it will be immediately available to hundreds of thousands of users. You are not limited to just the official Market, as there are alternatives. For example, you can publish the application on your blog. Amazon is rumored to be preparing its own Android application store.
  • As well as the SDK technical documentation, new resources are being created for Android developers. The platform is gaining increasing popularity among users and developers.

Enough talking - let's start developing Android apps!

Installing Eclipse and Android SDK

Orientation to the Android platform during development

Before you start writing applications for Android, you need to download the SDK for the Android platform. Each platform has its own version of Android SDK, which is installed on users' devices. For Android version 1.5 and higher, there are two platforms: Android Open Source Project and Google.

Android Open Source Project is an open source platform source code, but does not include Google extensions, such as Google Maps. If you don't want to use the Google API, the functionality Google Maps will not be available for your application. Unless you have a specific reason to do this, I would recommend that you target on one of Google's platforms, as this will allow you to use Google's own extensions.

  • Select Window->Android SDK and AVD Manager.
  • Click Available Packages in the left column and check the repository to show a list of available Android platforms.
  • You can select platforms to download from the list or leave all checked to download all available platforms. Once complete, click Install Selected and follow the installation instructions.

Once everything has been successfully downloaded, you are ready to start developing for Android.

Creating a New Android Project

The Eclipse New Project Wizard helps you create an Android application by generating files and code ready to run to the right of the block. This quick way to ensure functionality and a good starting point when starting application development:

After clicking Finish, Eclipse will create a new Android project, ready to run and develop on Android. Remember when you told Eclipse to generate an Activity called BrewClockActivity? This is the code that Android actually uses to run the application. The generated code will be displayed as a simple 'Hello World' style message.

Packages

The package name is an identifier for your application. When it comes time to publish the result to the Android Market, this ID will be used to track updates for the application, so it is important to ensure that this ID is unique. Although we are using the name com.example.brewclock here, for a real application it would be better to choose something like com.yourcompanyname.yourapplication.

SDK versions

Min SDK Version (the name speaks for itself) - the earliest Android version, on which the application will run. With each new Android release, the SDK adds and changes various methods. When you select an SDK version, Android (and the Android Market) knows that your app will only run on devices running the specified Android platform version and higher.

Launching your application

Now let's try to run our application in Eclipse. Since this is the first run, Eclipse will ask which project type you are working with:

  • Select Run->Run or press Ctrl+F11.
  • Select Android Application and click OK.

Eclipse will try to run the application on the Android device. On this moment, however, you do not have devices running Android control, so the project will fail to run and you will be prompted to create a new Android Virtual Device (AVD).

Virtual devices (Android Virtual Devices)

Android Virtual Device (AVD) emulates the Android environment, be it mobile phone or tablet PC. You can create as many AVD devices as you like, with different versions of the Android platform. For each AVD, you can configure various device parameters, indicating the presence of a physical keyboard, GP support, camera resolution, and so on.

Before you run the application, you must create your first AVD device with the Platform SDK (Google API, 1.6).

Let's do it now:

  • If you haven't tried running the application yet, click Run (or the keyboard shortcut Ctrl+F11)
  • When a warning pops up, click Yes to create the AVD.
  • Click New in the Android SDK and AVD Manager dialog.
  • Set the following parameters for AVD: Name: Android_1.6 Target: Google APIs (Google Inc.) - API Level 4 SD Card Size: 16 MiB Skin Built In: Default (HVGA)
  • Click Create AVD.
  • Close the Android SDK and AVD Manager dialog.

Running the code

Try running the application again (Ctrl + F11). Eclipse will now create your project and launch a new AVD. Remember, AVD completely emulates the Android environment, and you don't even have to observe the rather slow boot process that is the case with a real device. For this reason, once the AVD is ready to go, it's best to keep the window open while you're done programming for the entire day.

Android development: user interface design

One of the first steps to creating any program at all is designing the user interface. Here's a short sketch of our application:

The user will be able to set the boiling time in minutes using the + and - buttons. When he presses Start, the time will begin to count down for the specified number of minutes. If the user cancels boiling by pressing the button again, the time will be increased when the timer reaches 0.

Interface construction

Custom Android interface, or wrapper, which are described in the XML documentation, can be found in the res/layouts folder. The template code, already generated by Eclipse, is declared in res/layouts/main.xml and, as you notice, is already running in the emulator.

Eclipse has its own layout tool that allows you to create a drag-and-drop interface across the screen. However, at times it is easier to write the interface in XML and use a graphical layout to preview the results.

Let's do it now by changing main.xml as per the sketch above:

  • Open res/layouts/main.xml in Eclipse double click from Package Explorer.
  • Select the main.xml tab at the bottom of the screen to enter XML mode.

Now let's change the contents of main.xml to the following:

# /res/layouts/main.xml


Top