Sie sind auf Seite 1von 65

Developing an Android Application

By David Sudharsan R

Agenda

What is Android?
Android Features
Android Architecture
Application Components
Setting up the Development Environment
Developing an Application
Building an Application
Testing the Application using Emulator
Testing the Application using a Device
Debugging the Application
Publishing the Application

10 February 2012

What is Android

A software stack for mobile devices that includes an operating


system, middleware and key applications.
The first complete, open and free mobile platform.
Developed by the Open Handset Alliance (Google, Intel, Sony,
Samsung, Sprint, HTC, Motorola, T-Mobile, LG, Toshiba, Vodafone,
eBay, etc.).
Android SDK provides the tools and APIs necessary to begin
developing applications on the Android platform using the Java
programming language.

10 February 2012

Android Features

Application framework enables reuse and replacement of components.


Dalvik virtual machine optimized Java Virtual Machine for mobile devices.
Integrated browser based on the open source WebKit engine.
Optimized graphics powered by a custom 2D graphics library; 3D graphics
based on the OpenGL ES 1.0 specification (hardware acceleration
optional).
SQLite for structured data storage.
Media support for common audio, video, and still image formats (MPEG4,
H.264, MP3, AAC, AMR, JPG, PNG, GIF).
GSM Telephony (hardware dependent).
Bluetooth, EDGE, 3G, and WiFi (hardware dependent).
Camera, GPS, compass, and accelerometer (hardware dependent).
Rich development environment including a device emulator, tools for
debugging, memory and performance profiling, and a plugin for the Eclipse
IDE.

10 February 2012

Android Architecture

10 February 2012

Android Architecture (contd..)

Kernel
Android relies on Linux version 2.6 for core system services such as security,
memory management, process management, network stack, and driver model.
The kernel acts as an abstraction layer between the hardware and the rest of the
software stack.

Runtime
Android includes a set of core libraries that provides most of the functionality
available in the core libraries of the Java programming language.
Android application runs in its own process, with its own instance of the Dalvik
Virtual Machine (VM).
The Dalvik VM executes files in the Dalvik Executable .dex format which is
optimized for minimal memory footprint.
The VM is register-based, and runs classes compiled by a Java language
compiler that have been transformed into the .dex format by the included "dx"
tool.
The Dalvik VM relies on the Linux kernel for underlying functionality such as
threading and low-level memory management.

10 February 2012

Android Architecture (contd..)

Libraries
Android includes a set of C/C++ libraries used by various components of the
Android system.
System C library - a BSD-derived implementation of the standard C system
library (libc), tuned for embedded Linux-based devices
Media Libraries - based on PacketVideo's OpenCORE; the libraries support
playback and recording of many popular audio and video formats, as well as
static image files, including MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG
Surface Manager - manages access to the display subsystem and seamlessly
composites 2D and 3D graphic layers from multiple applications
LibWebCore - a modern web browser engine which powers both the Android
browser and an embeddable web view
SGL - the underlying 2D graphics engine
3D libraries - an implementation based on OpenGL ES 1.0 APIs; the libraries
use either hardware 3D acceleration (where available) or the included, highly
optimized 3D software rasterizer
FreeType - bitmap and vector font rendering
SQLite - a powerful and lightweight relational database engine available to all
applications
10 February 2012

Android Architecture (contd..)

Application Framework
Android offers developers the ability to build extremely rich and innovative
applications.
Developers can take advantage of the device hardware, access location
information, run background services, set alarms, add notifications to the status
bar, and much, much more.
The application architecture is designed to simplify the reuse of components.
View system is a rich and extensible set of Views that can be used to build an
application, including lists, grids, text boxes, buttons, and even an embeddable
web browser.
Content Providers enable applications to access data from other applications
(such as Contacts), or to share their own data.
Resource Manager, provides access to non-code resources such as localized
strings, graphics, and layout files.
Notification Manager enables all applications to display custom alerts in the
status bar.
Activity Manager manages the lifecycle of applications and provides a common
navigation back stack.

10 February 2012

Android Architecture (contd..)

Application
Android will ship with a set of core applications including an email client, SMS
program, calendar, maps, browser, contacts, and others.
All applications are written using the Java programming language.
Underlying all applications is a set of services and systems, including views,
activities, content providers, resources, intents, etc.
The Android SDK tools compile the code along with any data and resource files
into an Android package, an archive file with an .apk suffix.
A single .apk file is considered to be one application and is the file that Androidpowered devices use to install the application.
Every application runs in its own Linux process. Each process has its own virtual
machine (VM), so an application's code runs in isolation from other applications.
Each application, by default, has access only to the components that it requires
to do its work and no more.
An application can request permission to access device data such as the user's
contacts, SMS messages, the mountable storage (SD card), camera, Bluetooth,
and more. All application permissions must be granted by the user at install time.

10 February 2012

Application Components

Activities
An activity represents a single screen with a user interface.
For example, an email application might have one activity that shows a list of
new emails, another activity to compose an email, and another activity for
reading emails.
An activity is implemented as a subclass of Activity.

Services
A service is a component that runs in the background to perform long-running
operations or to perform work for remote processes.
A service does not provide a user interface. For example, a service might play
music in the background while the user is in a different application.
A service is implemented as a subclass of Service.

10 February 2012

10

Application Components (contd..)

Content providers
A content provider manages a shared set of application data.
You can store the data in the file system, an SQLite database, on the web, or
any other persistent storage location the application can access.
Through the content provider, other applications can query or even modify the
data.
For example the Contact content provider allows to view or add or modify
contacts.
A content provider is implemented as a subclass of ContentProvider.

Broadcast receivers
A broadcast receiver is a component that responds to system-wide broadcast
announcements.
Many broadcasts originate from the systemfor example, a broadcast
announcing that the screen has turned off.
A broadcast receiver is implemented as a subclass of BroadcastReceiver.

10 February 2012

11

Application Components (contd..)

Intents
Activities, services, and broadcast receivers are activated by an asynchronous
message called an intent.
Intents binds individual components to each other at runtime whether the
component belongs to your application or another.
An intent is created with an Intent object, which defines a message to activate
either a specific component or a specific type of component, an intent can be
either explicit or implicit, respectively.
For activities and services, an intent defines the action to perform (for example,
to "view" or "send" something) and may specify the URI of the data to act on. For
example, an intent might convey a request for an activity to show an image or to
open a web page.
For broadcast receivers, the intent simply defines the announcement being
broadcast.
The content provider, is not activated by intents. It is activated when targeted by
a request from a ContentResolver.

10 February 2012

12

Application Components (contd..)

Manifest file
The application must declare all its components in the Manifest file, which must
be at the root of the application project directory.
To identify any user permissions the application requires, such as Internet
access or read-access to the user's contacts.
To declare the minimum API Level required by the application, based on which
APIs the application uses.
To declare hardware and software features used or required by the application,
such as a camera, bluetooth services, or a multitouch screen.
To declare the API libraries the application needs to be linked against (other than
the Android framework APIs), such as the Google Maps library.

10 February 2012

13

Application Components (contd..)

Resources
An Android application is composed of other resources such as images, audio
files, and anything relating to the visual presentation of the application.
Application resources makes it easy to update various characteristics of your
application without modifying code such as different languages and screen sizes.
For every resource in the Android project, the SDK build tools define a unique
integer ID, which can be used to reference the resource from your application
code or from other resources defined in XML.

10 February 2012

14

Setting up the Development Environment

Download the Android SDK


(http://developer.android.com/sdk/index.html)
Check your development machine for system requirements
(http://developer.android.com/sdk/requirements.html)
Install Eclipse 3.5 (Galileo) or greater
Install ADT Plugin for Eclipse
Configure Android SDK and AVD

10 February 2012

15

Installing ADT Plugin


1. In Eclipse click Install New Software under the Help menu

10 February 2012

16

Installing ADT Plugin


2. Click Add and provide the ADT Plugin repository URL as in the
screenshot below.

10 February 2012

17

Installing ADT Plugin


3. Select the Developer Tools check box and click Next >

10 February 2012

18

Installing ADT Plugin


4. Click Next > and then accept the terms and conditions and click
Finish

10 February 2012

19

Installing ADT Plugin


5. The Installation is complete

10 February 2012

20

Installing ADT Plugin


6. In the preference update the Android SDK path

10 February 2012

21

Configuring Android SDK


1. The Android SDK can be configured by launching the SDK manager
under Windows in Eclipse menu or through the exe in the installed path

10 February 2012

22

Configuring Android SDK


2. Select the SDKs and other APIs needed for development, then click
Install packages

10 February 2012

23

Configuring Android SDK


3. Review the selected packages, accept the licensing and then click
Install

10 February 2012

24

Configuring Android SDK


4. Verify if the packages are installed by selecting Android in left pane
of the Eclipse Preferences

10 February 2012

25

Android Virtual Device


The Android Virtual Device (AVD) consists of:
A hardware profile: Defines the hardware features of the virtual
device. For example, define whether the device has a camera, whether
it uses a physical QWERTY keyboard or a dialing pad, how much
memory it has, and so on.
A mapping to a system image: Defines what version of the Android
platform will run on the virtual device.
Other options: Specify the emulator skin to use with the AVD, which
lets you control the screen dimensions, appearance, and so on. Also
specify the emulated SD card to use with the AVD.
A dedicated storage area on your development machine: the
device's user data (installed applications, settings, and so on) and
emulated SD card are stored in this area.

10 February 2012

26

Configuring AVD
1. The Android Virtual Devices (AVD) can be configured by launching
the AVD Manager from Eclipse menu under Windows or by the exe in
the installation path. Click New.. to configure a new device.

10 February 2012

27

Configuring AVD
2. Provide the configurations of the virtual device and then click Create
AVD

10 February 2012

28

Configuring AVD
3. The new AVD is created and added to the list

10 February 2012

29

Configuring AVD
4. Select the device to be launched and click Start... In the new window
displayed, click Launch

10 February 2012

30

Configuring AVD
5. The AVD is launched.

10 February 2012

31

Developing an Application
1. Create a new android Project in Eclipse

10 February 2012

32

Developing an Application
2. Provide the project details

10 February 2012

33

Developing an Application
3. Select the Android version for build

10 February 2012

34

Developing an Application
4. Provide the application details

10 February 2012

35

Developing an Application
5. Application structure created by Eclipse

10 February 2012

36

Developing an Application
6. Activity source code

10 February 2012

37

Developing an Application
7. Designing the layout for the activity

10 February 2012

38

Developing an Application
8. The layout in XML format

10 February 2012

39

Developing an Application
9. Defining the resources

10 February 2012

40

Developing an Application
10. Android Manifest file

10 February 2012

41

Building an Application
1. Building the application in Eclipse

10 February 2012

42

Building an Application
2. Build output files

10 February 2012

43

Building an Application
3. Build process

10 February 2012

44

Building an Application
4. Build steps

10 February 2012

45

Building an Application
The Build Steps:
The Android Asset Packaging Tool (aapt) takes the application resource files, such as
the AndroidManifest.xml file and the XML files for the Activities, and compiles them. An
R.java is also produced so resources can be referenced from Java code.
The aidl tool converts any .aidl interfaces into Java interfaces.
All of Java code, including the R.java and .aidl files, are compiled by the Java compiler
and .class files are output.
The dex tool converts the .class files to Dalvik byte code. Any 3rd party libraries and
.class files that are included in the project are also converted into .dex files so that they
can be packaged into the final .apk file.
All non-compiled resources (such as images), compiled resources, and the .dex files
are sent to the apkbuilder tool to be packaged into an .apk file.
Once the .apk is built, it must be signed with either a debug or release key before it can
be installed to a device.
Finally, if the application is being signed in release mode, align the .apk with the
zipalign tool. Aligning the final .apk decreases memory usage when the application is
running on a device.

10 February 2012

46

Building an Application
5. Build output

10 February 2012

47

Building an Application
6. Structure of resources.ap_

10 February 2012

48

Building an Application
7. Structure of .apk

10 February 2012

49

Testing an Application using Emulator


1. Running an application in the Emulator using the AVD

10 February 2012

50

Testing an Application using Emulator


2. Application in the AVD

10 February 2012

51

Testing an Application using a Device

Any Android-powered device can be used as an environment for


running, debugging, and testing your applications.
The tools included in the SDK makes it easy to install and run the
application on the device.
Applications can be installed on the device directly from Eclipse or
from the command line with ADB.

10 February 2012

52

Testing an Application using a Device


Declare the application as "debuggable" in the Android Manifest.
Set up the device to allow installation of non-Market applications.
Turn on "USB Debugging" on the device.
Set up the system to detect the device.
If developing on Windows install a USB driver for adb.
If developing on Mac OS X, it just works.
If developing on Ubuntu Linux, need to add a udev rules file that contains a USB
configuration for each type of device.

While using Eclipse, run or debug the application as usual. In the


Device Chooser dialog that lists the available emulator(s) and
connected device(s), select the device upon which to install and run
the application.

10 February 2012

53

Android Testing Framework

The Android testing framework, an integral part of the development


environment, provides an architecture and powerful tools that help to test
every aspect of the application at every level from unit to framework.
The testing framework has these key features:
Android test suites are based on JUnit. Plain JUnit can be used to test a class
that doesn't call the Android API, or Android's JUnit extensions to test Android
components.
The Android JUnit extensions provide component-specific test case classes.
These classes provide helper methods for creating mock objects and methods
that help to control the lifecycle of a component.
Test suites are contained in test packages that are similar to main application
packages.
The SDK tools for building and tests are available in Eclipse with ADT, and also
in command-line form for use with other IDES.
The SDK also provides monkeyrunner, an API testing devices with Python
programs, and UI/Application Exerciser Monkey, a command-line tool for stresstesting UIs by sending pseudo-random events to a device.

10 February 2012

54

Debugging an Application
1. Set the break points in the source code

10 February 2012

55

Debugging an Application
2. Launch the debugger

10 February 2012

56

Debugging an Application
3. Start the debugger

10 February 2012

57

Debugging an Application
4. Application in the debug mode

10 February 2012

58

Preparing Application for Release

10 February 2012

59

Publishing an Application

An application can be published using a hosted service such as


Android Market or through a web server or by directly sending the
package in email.
Android Market makes it easy for users of Android-powered devices
to see and download the application.
At any time after publishing an application on Android Market, an
update can be uploaded and published to the same application
package.

10 February 2012

60

Publishing an Application in Android Market

Android Market is a service that makes it easy for users to find and
download Android applications to their Android-powered devices,
either from the Android Market application on their device or from
the Android Market web site (market.android.com).
To publish an application on Android Market, first the developer
needs to register with the service using a Google account and agree
to the terms of service.
Once registered, the developer can upload the application to the
service whenever and update it as many times as required, and then
publish it when ready. Once published, users can see the
application, download it, and rate it.

10 February 2012

61

Publishing an Application in Android Market

Android Market offers a licensing service that lets developer enforce


licensing policies for paid applications that is published through
Android Market. With Android Market Licensing, the applications can
query Android Market at runtime to obtain the licensing status for the
user, then allow or disallow further use of the application as
appropriate.
Any application that is published through Android Market can use
the Android Market Licensing Service. The service uses no
dedicated framework APIs, so the licensing can be added to any
application that uses a minimum API Level of 3 or higher.
Android Market In-app Billing is an Android Market service that lets
the applications to sell digital content. This service can be used to
sell a wide range of content, including downloadable content such
as media files or photos, and virtual content such as game levels or
potions.

10 February 2012

62

Android Application Development Process

10 February 2012

63

References

https://knowmax.ultimatix.net
http://developer.android.com/sdk/index.html
http://developer.android.com/guide/index.html
http://developer.android.com/reference/packages.html
http://developer.android.com/resources/index.html

10 February 2012

64

Thank You

10 February 2012

65

Das könnte Ihnen auch gefallen