【正文】
ed by a particular ponent, Android makes sure that the application process of the ponent is running, starting it if necessary, and that an appropriate instance of the ponent is available, creating the instance if necessary. Activating ponents: intents Content providers are activated when they39。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 application39。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 work 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. It39。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 don39。s no longer needed and system resources are required by other applications. 2. Each process has its own virtual machine (VM), so application code runs in isolation from the code of all other applications. 3. By default, each application is assigned a unique Linux user ID. Permissions are set so that the application39。 7 Application Fundamentals Android applications are written in the Java programming language. The piled 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。返里有一個(gè)對(duì)先前例子的擴(kuò)展,其中加入了針對(duì) activity的兩個(gè) intent過(guò)濾器: 一個(gè)組件可以擁有任意數(shù)量的 intent過(guò)濾器,每個(gè)都聲明了一套不同的功能。但如果 intent沒(méi)有顯式地指定一個(gè)目標(biāo),Android就必須找到最合適的組件來(lái)響應(yīng)此 intent。未在manifest文件中進(jìn) 行聲明的 activity、 service以及 content provider將不為系統(tǒng)所見(jiàn),從而也就永不 會(huì)被運(yùn)行。除了聲明此應(yīng)用程序各個(gè)組件,它 會(huì)做很多其他工作,比如指明應(yīng)用程序所需鏈接到的庫(kù)的名稱(除了默認(rèn) 的 Android庫(kù)乀外)以及標(biāo)出應(yīng)用程序期望獲得的各種權(quán)限。稍后的組件的生命周期一節(jié),將對(duì)返種可能性及結(jié)果進(jìn) 行更詳細(xì)的認(rèn)論。 activity可以通過(guò)調(diào)用自身的 finish()方法來(lái)關(guān)閉。 而 activity則不同,它提供了用戶界面。 Android會(huì)調(diào)用所有對(duì)此廣播有興趣的 broadcast receiver的 onReceive()方法,將此 intent傳遞給它們。例如,一個(gè) activity可以建立一個(gè)不前述的音樂(lè)回放 service的連接,這 樣它就可以提供給用戶一些途徑(用戶界面)來(lái)控制回放。 2 通過(guò)傳遞一個(gè) Intent對(duì)象至 ()以啟動(dòng) 一個(gè) service(或 向正在運(yùn)行的 service給出一個(gè)新的指令)。 一個(gè) activity經(jīng)常啟動(dòng) 另一個(gè) activity。例如,它可以對(duì)所有感興趣的對(duì)象通報(bào)照相按鈕被按下。intent是一個(gè)保存著消息內(nèi)容的 Intent對(duì)象。 參閱獨(dú)立的 Content Providers文檔以獲得更多關(guān)于 使用 content provider的信息。數(shù)據(jù)可以存儲(chǔ)于文件系統(tǒng)、 SQLite數(shù)據(jù)庫(kù)或 其它有意丿的方式。然而,它們可以啟動(dòng) 一個(gè) activity來(lái)響應(yīng)它們收到的信息,或 者也可以使用 NotificationManager來(lái)通知用戶。應(yīng)用程序也可以發(fā)起廣播 —— 例如,通知其它應(yīng)用程序一些數(shù)據(jù)已經(jīng)下載到設(shè)備上并處于 可用狀態(tài)。所以它不會(huì)對(duì)其它組件或 用戶界面有任何妨礙,它們一般會(huì)派生 一個(gè)新線程來(lái)執(zhí)行一些時(shí)間消耗型任務(wù)(比如音樂(lè)回放)。 連接至(綁定到)一個(gè)正在運(yùn)行的 service(如果 service沒(méi)有運(yùn)行,則啟動(dòng)之)是可能 3 的。播放器應(yīng)用程序可能有一個(gè)或 多個(gè) activity來(lái)給用戶選擇歌曲并進(jìn) 行播放。) 2 Service service沒(méi)有可視化的用戶界面,而是在一段時(shí)間內(nèi)在后臺(tái)運(yùn)行。 Android 有一些預(yù)置的 view 供開(kāi)發(fā)者使用—— 包括按鈕、文本域、滾動(dòng) 條、菜單項(xiàng)、復(fù)選框等等。父級(jí) view 包含并組織其子 view 的布局。一般情況下,這個(gè)窗口是滿屏的,但它也可以是一個(gè)小的位于其它窗口之上的浮動(dòng) 窗口。每個(gè) activity 的作用,以及有多少個(gè) activity,當(dāng)然是取決于 應(yīng)用程序及 其設(shè)計(jì)的。一個(gè)短消息應(yīng)用程序可以包括一 2 個(gè)用于 顯示要發(fā)送消息到的聯(lián)系人列表的 activity,一個(gè)給選定的聯(lián)系人寫短信的 activity以及翻閱以前的短信或 改變?cè)O(shè)置的其他 activity。 為達(dá)到這 個(gè)目的,系統(tǒng)必須能 夠在一個(gè)應(yīng)用程序的任何一部分被需要時(shí)啟動(dòng)一個(gè)此應(yīng)用程序的進(jìn) 程,并將那個(gè)部分的 Java對(duì)象實(shí)例化。 1 應(yīng)用程序組件 Android的一個(gè)核心特性就是一個(gè)應(yīng)用程序可以使用其它應(yīng)用程序的元素(如果那 個(gè)應(yīng)用程序允許的話)。 從多個(gè)角度來(lái)看,每個(gè) Android應(yīng)用程序都存在于它自己的世界之中: 1 默 認(rèn) 情況下,每個(gè)應(yīng)用程序均運(yùn)行 于 它自己的 Linux進(jìn) 程中。 本科畢業(yè)設(shè)計(jì)(論文) 外文參考文獻(xiàn)譯文及原文 學(xué) 院 計(jì)算機(jī)學(xué)院 專 業(yè) 計(jì)算機(jī)科學(xué)與技術(shù) 年級(jí)班別 2021級(jí)( 6)班