Devel/building-blocks

From Android中文网

(重定向自构建组成模块) Android中文网(androidcn.net) 版权申明 : creativecommons licenses
Jump to: navigation, search

目录

[编辑] Android应用构成

Android应用是由各种各样的组件来构成. 这些组件大部分都是松散联接,你可以精确的描述它们的联接程度,所以组建的联合比单个程序更有结合力.

显然,所有的组件运行在同一个系统进程里面.在这个进程里面创建多线程是可以允许的,并且是常见的.如果你需要,也可以对刚才那个系统进程创建相互独立的子进程.即使会有很多实例运行,但是他们之间互不干扰,这个是很难得的,因为Android可以确保代码是进程间透明的.

以下部分是很重要的Android APIs;

[编辑] AndroidManifest.xml

AndroidManifest.xml 是控制文件,告诉所有由高级组件构成的系统可以做什么.这些高级的组件包括(特殊activities,服务,接收器,第三方提供商).控制文件用来告诉系统如何使用你所创建的组件.

[编辑] Activities

Activity 是一个有生命周期的对象. 一个Activity做一些工作需要相当大的数量的代码;如必要的话,这部分工作还可能包括对用户UI界面的显示,也可能是没有UI界面.代表性地解释Activity就是,你必须标明你应用程序的入口点.

[编辑] Views

视图(Views)可以将其自身绘制到屏幕(screen)上。Android的接口都是由一组以树的形式出现的视图组成的。开发者可以通过创建一个新的视图的方法来使用自定义的图形处理技术(比如开发游戏,或者是使用了不常用的用户图形(UI)窗口界面(widget))。

[编辑] Intents

Intents是一个消息操作对象.如果一个应用程序想要显示一个网页,那么它表示为Intent,我们可以通过Intent实例创建一个URI视图并且可以手工断开系统.系统设置一些代码(例如浏览器),可以让我们知道如果去操作Intent并且运行它.Intents 也可以被用于广播系统范围内的有效事件(例如播发一则通知).
An Intent is a simple message object that represents an "intention" to do something. For example, if your application wants to display a web page, it expresses its "Intent" to view the URI by creating an Intent instance and handing it off to the system.

The system locates some other piece of code (in this case, the Browser) that knows how to handle that Intent, and runs it. Intents can also be used to broadcast interesting events (such as a notification) system-wide.

[编辑] Services

服务是运行在后台的一段代码.它可以运行在它自己的进程,也可以运行在其他应用程序的进程里面,这要取决于自身的需要. 其他组件绑定到这个服务上面,并且可以请求远程方法调用.例如媒体播放器的服务,甚至当用户退出媒体用户向导界面,音乐依然可以持续播放.甚至当用户界面关闭,音乐播放依然继续.
A Service is a body of code that runs in the background. It can run in its own process, or in the context of another application's process, depending on its needs. Other components "bind" to a Service and invoke methods on it via remote procedure calls. An example of a Service is a media player; even when the user quits the media-selection UI, she probably still intends for her music to keep playing. A Service keeps the music going even when the UI has completed.

[编辑] Notifications

通知将以小图标的形式呈现在状态栏里.收到消息以后,用户可以与图标进行交互式操作.大部分熟知的通知是以短信息,通话记录,语音邮件的形式创建出来.通知是提请用户注意的重要机制.
A Notification is a small icon that appears in the status bar. Users can interact with this icon to receive information. The most well-known notifications are SMS messages, call history, and voicemail, but applications can create their own. Notifications are the strongly-preferred mechanism for alerting the user of something that needs their attention.

[编辑] ContentProviders

ContentProvider是访问数据设备的提供者.典型的例子是访问用户联系列表.你的应用程序需要访问的数据可以由ContentProvider来支持.并且你也可以定义自己专用数据的ContentProviders.

A ContentProvider is a data storehouse that provides access to data on the device; the classic example is the ContentProvider that's used to access the user's list of contacts. Your application can access data that other applications have exposed via a ContentProvider, and you can also define your own ContentProviders to expose data of your own.

Personal tools