【正文】
其它一些信息。而對于broadcast receiver來說, Intent對象指明了所通報的操作。 對于 每種組件來說,激活的方法是不 同的: 1 通過傳遞一 ()(以啟動(或 指定新工作給)一個 activity。 Android通過調(diào)用 activity的 onNewIntent()方法來傳遞給它隨后的任何 intent。 如果它期望它所啟動 的那個 activity迒回一個結(jié)果,它會調(diào)用 startActivityForResult()而不 是 startActivity()。其結(jié)果將會被封裝在一個 Intent對象中,并傳遞給發(fā)出調(diào)用的 activity的 onActivityResult() 方法。 Android調(diào)用此 service的 onStart()方法并將 Intent對象傳遞給它。此 service會通過 onBind() 方法的調(diào)用來獲取此 Intent對象(如果此 service尚未運行, bindService()會先啟動 它)。這 個 activity可以調(diào)用 bindService()來建立此連接,然后調(diào)用 service中定之的方法來控制回放。 3 應(yīng)用程序可以通過傳遞一個 Intent對象至 () , Context. sendOrderedBroadcast(), 以及 ()和其它類似方法來發(fā)起一個廣播。 5 關(guān)閉組件 content provider僅在響應(yīng)來自 ContentResolver的請求時處于活動 狀態(tài)。所以沒有必要去顯式地關(guān)閉返些組件。只 要會話依然持續(xù),無論會話過程有無空閑,activity同用戶進 行長時 間會話且可能一直處于活動狀態(tài)。所以 Android為關(guān)閉 activity和 service提供了一系列有序的方法。一個 activity可以通過調(diào)用finishActivity()方法來關(guān)閉另外一個 activity(它用 startActivityForResult() 啟動的)。 系統(tǒng)也會在組件不 再被使用的時候戒者當(dāng) Android必須為更多的活動 組件回 收內(nèi)存時關(guān)閉它。 manifest文件 當(dāng) Android啟動 一個應(yīng)用程序組件之 前,它必須知道那個組件是存在的。 manifest文件是一個結(jié)構(gòu)化的 XML文件,而且對于 所有應(yīng)用程序,文件名總是。 activity元素的 name屬性指定了實現(xiàn)此 activity的 Activity子類。 其它組件也以類似的方法聲明 —— service 元素用于 聲明 service, receiver 元素用于 聲明 broadcast receiver,而 provider 元素用于 聲明 content provider。然而, broadcast receiver既可以在 manifest文件中聲明,也可以在 6 代碼中動 態(tài)創(chuàng)建( 為 BroadcastReceiver對象),并以調(diào)用 ()的方式注冊至系統(tǒng)。如果進 行了返種指定, Android會找到這個組件(基于 manifest文件中的聲明)并激活它。這 個過程是通過比較 Intent對象和所有潛在目標的 intent過濾器完成的。如同組件的其它必要信息一樣,這 些 intent過濾器是在 manifest文件中進 行聲明的。如果組件沒有包含任何過濾器,它只能被顯式 地指明作為目標組件的 intent激活。其它所有的過濾 器都在 manifest文件中設(shè)置。 it39。s code needs to be executed, and shuts down the process when it39。s files are visible only to that user and only to the application itself — although there are ways to export them to other applications as well. It39。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 doesn39。t have a single entry point for everything in the application (no main() function, for example). Rather, they have essential ponents that the system can instantiate and run as needed. There are four types of ponents: 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 8 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 acplished by having the current activity start the next one. 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 popup 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 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 anize the layout of their children. Leaf views (those at the bottom of the hierarch