【正文】
nse in the midst of the activity, or a window that presents users with vital information when they select a particular item onscreen.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 activity39。s window by the () 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.)ServicesA service doesn39。s possible to connect to (bind to) an ongoing service (and start the service if it39。t block other ponents or the user interface, they often spawn another thread for timeconsuming tasks (like music playback). See Processes and Threads, later.Broadcast receiversA broadcast receiver is a ponent 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 user39。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。s involved.See the separate Content Providers document for more information on using content providers.Whenever there39。re targeted by a request from a ContentResolver. The other three ponents — activities, services, and broadcast receivers — are activated by asynchronous messages called intents. An intent is an Intent object that holds the content of the message. For activities and services, it names the action being requested and specifies the URI of the data to act on, among other things. For example, it might convey a request for an activity to present an image to the user or let the user edit some text. For broadcast receivers, theIntent object names the action being announced. For example, it might announce to interested parties that the camera button has been pressed.There are separate methods for activating each type of ponent:1. An activity is launched (or given something new to do) by passing an Intent object to() or (). The responding activity can look at the initial intent that caused it to be launched by calling its getIntent() method. Android calls the activity39。s starting, it calls startActivityForResult() instead of startActivity(). For example, if it starts an activity that lets the user pick a photo, it might expect to be returned the chosen photo. The result is returned in an Intent object that39。s onActivityResult() method.2. A service is started (or new instructions are given to an ongoing service) by passing an Intent object to (). Android calls the service39。s responding to a request from a ContentResolver. And a broadcast receiver is active only while it39。s no need to explicitly shut down these ponents.Activities, on the other hand, provide the user interface. They39。s bundled into the Android package, the .apk file that also holds the application39。s ponents, such as naming any libraries the application needs to be linked against (besides the default Android library) and identifying any permissions the application expects to be granted.But the principal task of the manifest is to inform Android about the application39。s intent filters inform Android of the kinds of intents the ponent is able to handle. Like other essential information about the ponent, they39。s an extension of the previous example that adds two intent filters to the activity:The first filter in the example — the bination of the action and the category — is a mon one. It marks the activity as one that should be represented in the application launcher, the screen listing applications users can launch on the device. In other words, the activity is the entry point for the application, the initial one users would see when they choose the application in the launcher.The second filter declares an action that the activity can perform on a particular type of data.A ponent can have any number of intent filters, each one declaring a different set of capabilities. If it doesn39。s created and registered in code, the intent filter is instantiated directly as anIntentFilter object. All other filters are set up in the manifest.For more on intent filters, see a separate document, Intents and Intent Filters.漢語譯文應(yīng)用程序基礎(chǔ)Android應(yīng)用程序使用Java編程語言開發(fā)。該文件是分發(fā)并安裝應(yīng)用程序到移動設(shè)備的載體,是用戶下載到他們的設(shè)備的文件。當(dāng)應(yīng)用程序中的任何代碼需要被執(zhí)行時,Android啟動此進(jìn)程,而當(dāng)不再需要此進(jìn)程并且其它應(yīng)用程序又請求系統(tǒng)資源時,則關(guān)閉這個進(jìn)程。 2 每個進(jìn)程都有其獨有的虛擬機(VM),所以應(yīng)用程序代碼與所有其它應(yīng)用程序代碼是隔離運行的。1 應(yīng)用程序組件Android的一個核心特性就是一個應(yīng)用程序可以使用其它應(yīng)用程序的元素(如果那個應(yīng)用程序允許的話)。你的應(yīng)用程序并沒有吸納或鏈接其它應(yīng)用程序的代碼。為達(dá)到這個目的,系統(tǒng)必須能夠在一個應(yīng)用程序的任何一部分被需要時啟動一個此應(yīng)用程序的進(jìn)程,并將那個部分的Java對象實例化。一共有四種組件類型:1 Activity activity是為用戶操作而展示的可視化用戶