Android-The-Developers-Guide.pdf

(25096 KB) Pobierz
What is Android? | Android Developers
What is Android? | Android Developers
29.04.09 0:33
What is Android?
Android is a software stack for mobile devices that includes an operating system, middleware and key applications.
The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform
using the Java programming language.
Features
Application framework enabling reuse and replacement of components
Dalvik virtual machine optimized 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
Android Architecture
The following diagram shows the major components of the Android operating system. Each section is described in
more detail below.
http://developer.android.com/guide/basics/what-is-android.html
Page 1 of 3
390270650.005.png 390270650.006.png
What is Android? | Android Developers
29.04.09 0:33
Applications
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.
Application Framework
Developers have full access to the same framework APIs used by the core applications. The application architecture is
designed to simplify the reuse of components; any application can publish its capabilities and any other application
may then make use of those capabilities (subject to security constraints enforced by the framework). This same
mechanism allows components to be replaced by the user.
Underlying all applications is a set of services and systems, including:
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 that enable applications to access data from other applications (such as Contacts), or to share
their own data
A Resource Manager , providing access to non-code resources such as localized strings, graphics, and layout files
A Notification Manager that enables all applications to display custom alerts in the status bar
http://developer.android.com/guide/basics/what-is-android.html
Page 2 of 3
390270650.007.png
What is Android? | Android Developers
29.04.09 0:33
An Activity Manager that manages the lifecycle of applications and provides a common navigation backstack
For more details and a walkthrough of an application, see the Notepad Tutorial .
Libraries
Android includes a set of C/C++ libraries used by various components of the Android system. These capabilities are
exposed to developers through the Android application framework. Some of the core libraries are listed below:
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
Android Runtime
Android includes a set of core libraries that provides most of the functionality available in the core libraries of the Java
programming language.
Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been
written so that a device can run multiple VMs efficiently. 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.
Linux 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 also acts as an abstraction layer between the hardware and
the rest of the software stack.
Except as noted, this content is licensed under Apache 2.0 . For details and restrictions, see the Content License .
Android 1.5 r1 - 27 Apr 2009 0:19
Go to top
http://developer.android.com/guide/basics/what-is-android.html
Page 3 of 3
390270650.008.png 390270650.001.png
Application Fundamentals | Android Developers
29.04.09 0:33
Application Fundamentals
Android applications are written in the Java programming language. The compiled Java code — along with any data
and resource files required by the application — is bundled by the aapt tool into an Android package , an archive file
marked by an .apk suffix. This file is the vehicle for distributing the application and installing it on mobile devices; it's
the file users download to their devices. All the code in a single .apk file is considered to be one application .
In many ways, each Android application lives in its own world:
By default, every application runs in its own Linux process. Android starts the process when any of the
application's code needs to be executed, and shuts down the process when it's no longer needed and system
resources are required by other applications.
Each process has its own Java virtual machine (VM), so application code runs in isolation from the code of all
other applications.
By default, each application is assigned a unique Linux user ID. Permissions are set so that the application's files
are visible only that user, only to the application itself — although there are ways to export them to other
applications as well.
It's possible to arrange for two applications to share the same user ID, in which case they will be able to see each
other's files. To conserve system resources, applications with the same ID can also arrange to run in the same Linux
process, sharing the same VM.
Application Components
A central feature of Android is that one application can make use of elements of other applications (provided those
applications permit it). For example, if your application needs to display a scrolling list of images and another
application has developed a suitable scroller and made it available to others, you can call upon that scroller to do the
work, rather than develop your own. Your application doesn't incorporate the code of the other application or link to it.
Rather, it simply starts up that piece of the other application when the need arises.
For this to work, the system must be able to start an application process when any part of it is needed, and instantiate
the Java objects for that part. Therefore, unlike applications on most other systems, Android applications don't have a
single entry point for everything in the application (no main() function, for example). Rather, they have essential
components that the system can instantiate and run as needed. There are four types of components:
Activities
An activity presents a visual user interface for one focused endeavor the user can undertake. For example, an
activity might present a list of menu items users can choose from or it might display photographs along with their
captions. A text messaging application might have one activity that shows a list of contacts to send messages to,
a second activity to write the message to the chosen contact, and other activities to review old messages or
change settings. Though they work together to form a cohesive user interface, each activity is independent of the
others. Each one is implemented as a subclass of the Activity base class.
An application might consist of just one activity or, like the text messaging application just mentioned, it may
contain several. What the activities are, and how many there are depends, of course, on the application and its
design. Typically, one of the activities is marked as the first one that should be presented to the user when the
application is launched. Moving from one activity to another is accomplished by having the current activity start the
next one.
http://developer.android.com/guide/topics/fundamentals.html
Page 1 of 19
390270650.002.png 390270650.003.png
Application Fundamentals | Android Developers
29.04.09 0:33
Each activity is given a default window to draw in. Typically, the window fills the screen, but it might be smaller
than the screen and float on top of other windows. An activity can also make use of additional windows — for
example, a pop-up dialog that calls for a user response in the midst of the activity, or a window that presents
users with vital information when they select a particular item on-screen.
The visual content of the window is provided by a hierarchy of views — objects derived from the base View class.
Each view controls a particular rectangular space within the window. Parent views contain and organize the layout
of their children. Leaf views (those at the bottom of the hierarchy) draw in the rectangles they control and respond
to user actions directed at that space. Thus, views are where the activity's interaction with the user takes place.
For example, a view might display a small image and initiate an action when the user taps that image. Android
has a number of ready-made views that you can use — including buttons, text fields, scroll bars, menu items,
check boxes, and more.
A view hierarchy is placed within an activity's window by the Activity.setContentView() method. The
content view is the View object at the root of the hierarchy. (See the separate User Interface document for more
information on views and the hierarchy.)
Services
A service doesn't have a visual user interface, but rather runs in the background for an indefinite period of time.
For example, a service might play background music as the user attends to other matters, or it might fetch data
over the network or calculate something and provide the result to activities that need it. Each service extends the
Service base class.
A prime example is a media player playing songs from a play list. The player application would probably have one
or more activities that allow the user to choose songs and start playing them. However, the music playback itself
would not be handled by an activity because users will expect the music to keep playing even after they leave the
player and begin something different. To keep the music going, the media player activity could start a service to
run in the background. The system would then keep the music playback service running even after the activity
that started it leaves the screen.
It's possible to connect to (bind to) an ongoing service (and start the service if it's not already running). While
connected, you can communicate with the service through an interface that the service exposes. For the music
service, this interface might allow users to pause, rewind, stop, and restart the playback.
Like activities and the other components, services run in the main thread of the application process. So that they
won't block other components or the user interface, they often spawn another thread for time-consuming tasks
(like music playback). See Processes and Threads , later.
Broadcast receivers
A broadcast receiver is a component that does nothing but receive and react to broadcast announcements. Many
broadcasts originate in system code — for example, announcements that the timezone has changed, that the
battery is low, that a picture has been taken, or that the user changed a language preference. Applications can
also initiate broadcasts — for example, to let other applications know that some data has been downloaded to the
device and is available for them to use.
An application can have any number of broadcast receivers to respond to any announcements it considers
important. All receivers extend the BroadcastReceiver base class.
Broadcast receivers do not display a user interface. However, they may start an activity in response to the
information they receive, or they may use the NotificationManager to alert the user. Notifications can get the user's
attention in various ways — flashing the backlight, vibrating the device, playing a sound, and so on. They typically
place a persistent icon in the status bar, which users can open to get the message.
Content providers
A content provider makes a specific set of the application's data available to other applications. The data can be
stored in the file system, in an SQLite database, or in any other manner that makes sense. The content provider
extends the ContentProvider base class to implement a standard set of methods that enable other applications to
retrieve and store data of the type it controls. However, applications do not call these methods directly. Rather
they use a ContentResolver object and call its methods instead. A ContentResolver can talk to any content
provider; it cooperates with the provider to manage any interprocess communication that's involved.
http://developer.android.com/guide/topics/fundamentals.html
Page 2 of 19
390270650.004.png
Zgłoś jeśli naruszono regulamin