Free tutorials for Java, Eclipse and Web programming



Android Development with Eclipse - Tutorial

Lars Vogel

Version 1.7

13.01.2009

Revision History
Revision 0.104.07.2009Lars Vogel
Created
Revision 0.208.07.2009Lars Vogel
First working example
Revision 0.330.08.2009Lars Vogel
Improved description
Revision 0.430.10.2009Lars Vogel
Updated to use Android 2.0
Revision 0.501.11.2009Lars Vogel
Started XML support
Revision 0.602.11.2009Lars Vogel
Added the android log view
Revision 0.703.11.2009Lars Vogel
Access to the shell access, uninstall android application
Revision 0.804.11.2009Lars Vogel
Networking
Revision 0.905.11.2009Lars Vogel
Added the usage of SharedPreferences
Revision 1.006.11.2009Lars Vogel
Usage of ContentProvider
Revision 1.110.11.2009Lars Vogel
Assign handler to button via XML (thanks to Jason Arora for the tip)
Revision 1.221.11.2009Lars Vogel
Emulator console added
Revision 1.322.11.2009Lars Vogel
Authorization mentioned
Revision 1.425.11.2009Lars Vogel
Google API, location API, MapView
Revision 1.513.12.2009Lars Vogel
Fixed text for button assignment
Revision 1.630.12.2009Lars Vogel
Fixed typo
Revision 1.713.01.2009Lars Vogel
Updated screenshot

Programming with Google Android and Eclipse

This article describes how to create Android applications with Eclipse.

The article is based on Eclipse 3.5 and Android 2.0.


Table of Contents

1. Overview
1.1. Android
1.2. Android Application
2. Installation
2.1. Eclipse
2.2. Android
2.3. Configuration
2.4. Device
3. Your first Android project
3.1. Create Project
3.2. Add UI Elements
3.3. Create and use attributes
3.4. Code your applicatioin
3.5. Define the button handler
3.6. Start Project
3.7. Using the phone menue
4. Important views
4.1. Log
4.2. File explorer
5. Networking
5.1. Networking
5.2. Proxy
5.3. Permissions
5.4. Example
6. ContentProvider
6.1. Overview
6.2. Create Contacts
6.3. Example
7. Shell
7.1. Opening the Shell
7.2. Emulator Console
7.3. Uninstall an application
8. Location API
8.1. Device with Google API
8.2. Project and Permissions
8.3. Google Map library
8.4. Layout
8.5. Activity
8.6. Run and Test
9. Thank you
10. Questions and Discussion
11. Links and Literature
11.1. Source Code
11.2. Android Resources
11.3. Other Resources

1. Overview

1.1. Android

Android is an operating system based on Linux with a Java programming interface. It provides tools, e.g. a compiler, debugger and a device emulator as well as its own Java Virtual machine (Dalvik).

Android is created by the Open Handset Alliance which is lead by Google.

Android uses a special Java virtual machine (Dalvik) which is based on the Apache Harmony Java implementation. Dalvik uses a special Bytecode so that you have to use the Android compiler to create this special byte-code.

Android supports 2-D and 3-D graphics using the OpenGL libraries and supports data storage in a SQLLite database.

For development Google provides the Android Development Tools (ADT) for Eclipse to develop Android applications.

1.2. Android Application

An Android application consists out of the following parts:

  • Activity - A screen in the Android application

  • Intent / Broadcast Receiver - allow the application to request and / or provide services from other application. For example the application call ask via an intent for a contact application. Application register themself via an IntentFilter

  • Services - Background activities without UI

  • Content Provider - provides data to applications, Android contains a SQLLite DB which can serve as data provider

An Android application is described the file "AndroidManifest.xml". This files contains all classes of the application and the required permissions for the application, e.g. if the application requires network access. "AndroidManifest.xml" can be thought as the deployment descriptor for an Android application.