原文地址:http://developer.android.com/guide/topics/fundamentals.html

Overview

The Android operating system is amulti-user Linux system in which each application is a different user. Bydefault, the system assigns each application a unique Linux user ID. The systemsets permission for all the files in an application so that only the user IDassigned to that application can access them.

Each process has its own virtualmachine (VM), so an application’s codes runs in isolation from otherapplications. It’s possible to arrange for two applications to share the sameLinux user ID, in which case they are able to access each other’s files.Applications with the same user ID can also arrange to run in the same Linuxprocess and share the same VM (the applications must also be signed with thesame certificate).

Basic structure:

1.Code componentsdefine your application

2.Themanifest file declare components andrequired devices features for application

3.Resources thatseparate from the application code and allow application to gracefully optimizeits behavior for a variety of device configurations

Application Components

Application components are essentialbuilding blocks of an Android application. There are 4 different types ofapplication components. Each type serves a distinct purpose and has a distinctlifecycle that defines how the component is created and destroyed.

1.Activities

An activity represents a single screen with a user interface.

2.Services

A service is a component that runs inthe background to perform long-runningoperations or to perform work for remote processes. A service does not providea user interface. For example, play music in background or fetch data over thenetwork without blocking user interaction.

3.Content providers

A content provider manages a sharedset of application data. You canstore data in the file system, an SQLite database, on the web, or any otherpersistent storage location that application can access. Through the contentprovider, other applications can query or even modify the data. Contentproviders are also useful for reading and writing data that is private toapplication and not shared. For example, Note Pad sample application uses acontent provider to save notes.

4. Broadcast receivers

A broadcast receiver is a component that responds tosystem-wide broadcast announcements. Manybroadcasts originate from the system. For example, announcing the screen hasturned off, the battery is low, or picture was captured. Although broadcastreceivers don’t display a user interface, they may create a status barnotification to alert the user when a broadcast event occurs. For instance, itmight initiate a service to perform some work based on the event.

A unique aspect of the Android systemdesign is that any application can start another application’s component. Forexample, if application starts the activity in the camera application thatcaptures a photo, that activity runs in the process that belongs to the cameraapplication, not in your application’s process. Therefore, unlike applicationson most other systems, Android application don’t have single entry point (there’s no main function)

Activate Components

Application can’t directly activate acomponent from another application, but the Android system, can.

So, to activate a component inanother application, you must deliver a message to the system that specifiesyour intent to start a particular component. The system then activates thecomponent for you.

Activities, services, and broadcastreceivers are activated by an asynchronous message called an intent. Intents bind individual components to eachother at runtime. For activities and services, an intent defines the action toperform (for example, to “view” or “send” something) and may specify the URI ofthe data to act on. For broadcast receivers, the intent simply defines theannouncement being broadcast.

The other component type, contentprovider, is not activated by intents. Rather, it is activated when targeted bya request from a ContentResolver. The content resolver handles all directtransactions with the content provider so that the component doesn’t need toand instead calls methods on the ContentResolver object.

So, there are ways to activating eachtype of component:

· Start activity by passing an Intentto startActivity() or startActivityForResult() if you want resultreturned

· Start service by passing an Intent tostartService() or bindService()

· Initiate a broadcast by passing anIntent to methods like sendBroadcase(), sendOrderedBroadcase(), or sendStickBroadcast()

· Perform a query to a content providerby calling query() on a ContentResolver.

Manifest File

Before the Android system can startan application component, the system must know that the component exists byreading the application’s AndroidManifest.xmlfile. Application must declare all its components in this file, which must beat the root of the application project directory.

The manifest does a number of thingsin addition to declaring the application’s components, such as:

· Identify any user permissions theapplication requires

· Declare the minimum API levelrequired by the application

· Declare hardware and softwarefeatures used or required by the application, such as a camera, bluetooth ormulti-touch screen.

· API libraries the application needsto be linked against, such as the Google Maps library.

In <application>element, the android:icon attribute pointsto resources for an icon that identifies the application. In the <activity> element, the android:name attribute specifies the fullyqualified class name of the Activity subclass and android:labelattribute specifies a string to use as the user-visible label for theactivity.

You can use an intent to start activities, service and broadcastreceivers by explicitly naming the target component in the intent. However, thereal power of intents: with intent actions, you simply describe the type ofaction you want to perform and allow the system to find a component on thedevice that can perform the action and start it. If there are multiplecomponents available, then the user selects which one to use.

The way the system identifies thecomponents that can respond to an intent is by comparingthe intent received to the intent filters provided in the manifest file ofother applications on the device. When you declare a component in manifest, youcan optionally include intent filters that declare the capabilities of thecomponent so it can respond to intents from other application.

In order to categorize devices bytheir screen type, Android defines two characteristics for each device: Screen size (the physical dimensions of the screen),and Screen density (the physical density ofthe pixels on the screen, or dpi – dots per inch).

The Android system generalizes theminto select groups that make them easier to target:

The screen sizes are: small, normal,large, and extra large.

The screen densities are: lowdensity, medium density, high density, and extra high density.

For every resource that you include in yourAndroid project, the SDK build tools define a uniqueID, which you can use to reference the resource from your applicationcode or from other resources defined in XML.

更多相关文章

  1. JNI Examples for Android
  2. ch08 Android(安卓)Intent
  3. android 源码下载及问题
  4. Android(安卓)UI + Function
  5. Android中判断是否有声音在播放
  6. 【Android(安卓)应用开发】GitHub 优秀的 Android(安卓)开源项目
  7. Windows环境下Android(安卓)Studio v1.0安装教程、快捷方式
  8. 【Android(安卓)应用开发】GitHub 优秀的 Android(安卓)开源项目
  9. Android(安卓)-- 获取IP和MAC地址

随机推荐

  1. Android中AsyncTask(异步任务)和Handler(
  2. Xposed 实现给Hook的APP动态添加权限Perm
  3. Android(安卓)-- 工程目录解释
  4. Android布局案例之人人android九宫格
  5. Android开机速度 ------之ART预优化dex2o
  6. Android常用之Butterknife使用详解
  7. Android之简单了解Android OS内部机制
  8. Android中 在显示ImageView时图片上面和
  9. Android(安卓)init 详细过程分析
  10. 【转】获取android设备 id