Creating an eclipse project for android. Setting up Eclipse for Android development. Slow start emulator

In this guide, you will learn how to start developing for Android, namely: mobile applications on Android Eclipse platform + SDK. Today, there are many approaches to developing and building mobile apps 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 to choose? What programming language to learn? Which set of applications to choose for project planning? In this tutorial, you'll learn how to get started developing mobile apps for the Android platform, Google's open source mobile OS.

Why the 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 apps for every kind of hardware imaginable today. mobile devices- digital compasses, video cameras, GPS, sensors and more.

Free android development tools let you quickly start creating free or almost free apps. When you're ready to show the world your program, 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 Apple's App Store (which is very strict on eligibility), makes your app available for download and purchase after quick review- if the application does not violate the rules and the law.

Here are a few other Android SDK features that offer 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.
  • Given 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 the official Market, as there are alternatives. For example, you can publish the app on your blogs. Amazon is rumored to be preparing its own Android app store.
  • As well as the SDK technical documentation, new resources are being created for Android developers. The platform is gaining more and more popularity among users and developers.

Enough talk - let's start Android app development!

Installing Eclipse and Android SDK

Orientation for the Android platform during development

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

Android Open Source Project - 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 one of the Google 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. When finished, click Install Selected and follow the installation instructions.

Once everything has been successfully uploaded, you are ready to start Android development.

Create a new Android project

The Eclipse New Project Wizard will help you create an Android application by generating files and code ready to run on the right side of the block. This fast way make sure it works and a good starting point when starting to develop applications:

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

Packages

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

SDK versions

Min SDK Version (name speaks for itself) - the earliest android version on which the application will run. With every new release of Android, 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 Android platform version of the specified 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 you 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 under 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 settings such as physical keyboard, GP support, camera resolution, and so on.

Before running 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, press Run (or the keyboard shortcut Ctrl+F11)
  • When the 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 code

Try running the application again (Ctrl + F11). Eclipse will now create your project and launch the new AVD. Remember, AVD completely emulates the Android environment, and you don't even have to watch the slow boot process as you would with a real device. For this reason, once the AVD is ready to go, it's best not to close the window until you've finished programming, throughout the day.

Android Development: User Interface Design

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

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

Interface building

The Android user interface, or skin, which is 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 can see, is already running in the emulator.

Eclipse has its own layout design tool that allows you to create an interface by dragging and dropping within the screen. However, it is sometimes easier to write the interface in XML and use a graphical layout to preview the results.

Let's do it now by modifying main.xml to match the sketch above:

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

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

# /res/layouts/main.xml


Top