測控技術(shù)與儀器專業(yè)應(yīng)用程序基礎(chǔ)外文文獻(xiàn)翻譯_第1頁
測控技術(shù)與儀器專業(yè)應(yīng)用程序基礎(chǔ)外文文獻(xiàn)翻譯_第2頁
測控技術(shù)與儀器專業(yè)應(yīng)用程序基礎(chǔ)外文文獻(xiàn)翻譯_第3頁
測控技術(shù)與儀器專業(yè)應(yīng)用程序基礎(chǔ)外文文獻(xiàn)翻譯_第4頁
測控技術(shù)與儀器專業(yè)應(yīng)用程序基礎(chǔ)外文文獻(xiàn)翻譯_第5頁
已閱讀5頁,還剩23頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、測控技術(shù)與儀器專業(yè)應(yīng)用程序基礎(chǔ) 外文文獻(xiàn)翻譯1應(yīng)用程序基礎(chǔ)android應(yīng)用程序使用java編程語言開發(fā)。aapt工具把編譯 后的java代碼連同應(yīng)用程序所需的其他數(shù)據(jù)和資源文件一起打包 到一個android包文件中,這個文件使用.apk作為擴(kuò)展名。此文 件是分發(fā)并安裝應(yīng)用程序到移動設(shè)備的載體;是用戶下載到他們 的設(shè)備的文件。單一.apk文件中的所有代碼被認(rèn)為是一個應(yīng)用程從多個角度來看,每個android應(yīng)用程序都存在于它自己的 世界之中:1默認(rèn)情況下,每個應(yīng)用程序均運(yùn)行于它自己的linux進(jìn)程 中。當(dāng)應(yīng)用程序中的任何代碼需要被執(zhí)行時,android啟動此進(jìn)程, 而當(dāng)不再需要此進(jìn)程并且其它應(yīng)用

2、程序又請求系統(tǒng)資源時,則就關(guān)閉了這個進(jìn)程。2每個進(jìn)程都有其獨(dú)有的虛擬機(jī)(vm),所以應(yīng)用程序代碼 與所有其它應(yīng)用程序代碼是隔離運(yùn)行的。3默認(rèn)情況下,每個應(yīng)用程序均被賦予一個唯一的linux用 戶id,并加以權(quán)限設(shè)置,使得應(yīng)用程序的文件僅對此用戶及此應(yīng) 用程序可見盡管也有其它的方法使得這些文件同樣能為其他 應(yīng)用程序所訪問。1.1應(yīng)用程序組件android的一個核心的特性就是一個應(yīng)用程序可以使用其它 應(yīng)用程序的元素(如果那個應(yīng)用程序允許的話)。例如,如果你的 應(yīng)用程序需要顯示一個圖片卷動列表,而另一個應(yīng)用程序已經(jīng)開 發(fā)了一個合用的而又允許別的應(yīng)用程序使用的話,你可以直接調(diào) 用那個卷動列表來完成工作

3、,而不用自己再開發(fā)一個。你的應(yīng)用 程序并沒有吸納或鏈接其它應(yīng)用程序的代碼。它只是在有需求的 時候啟動了其它應(yīng)用程序的那個功能部分。為達(dá)到這個目的,系統(tǒng)必須能夠在一個應(yīng)用程序的任何一部 分被需要時啟動一個此應(yīng)用程序的進(jìn)程,并將那個部分的java對 象實例化。因此,不像其它大多數(shù)系統(tǒng)上的應(yīng)用程序,android 應(yīng)用程序并沒有為應(yīng)用程序提供一個單獨(dú)的入口點(diǎn)(比如說,沒 有mahio函數(shù)),而是為系統(tǒng)提供了可以實例化和運(yùn)行所需的必備 組件。一共有四種組件類型:(1) activityactivity是為用戶操作而展示的可視化用戶界面。例如,一個 activity可以展示一個菜單項列表供用戶選擇,戒者

4、顯示一些包含 說明文字的照片。一個短消息應(yīng)用程序可以包括一個用于顯示要 發(fā)送消息到的聯(lián)系人列表的activity, 個給選定的聯(lián)系人寫短信 的activity以及翻閱以前的短信或改變設(shè)置的其他activity。盡管 它們一起組成了一個內(nèi)聚的用戶界面,但其中每個activity都不其 它的保持獨(dú)立。每一個都實現(xiàn)為以activity類為基類的子類。一個應(yīng)用程序可以只有一個activity,戒者,如剛才提到的短 信應(yīng)用程序那樣,包含很多個。每個activity的作用,以及有多少 個activity,當(dāng)然是取決于應(yīng)用程序及其設(shè)計的。一般情況下,總 有一個應(yīng)用程序被標(biāo)記為用戶在應(yīng)用程序啟動的時候第一個看

5、到 的。從一個activity轉(zhuǎn)向另一個靠的是用當(dāng)前的activity啟動下一 個。每個activity都被給予一個默認(rèn)的窗口以進(jìn)行繪制。一般情況 下,這個窗口是滿屏的,但它也可以是一個小的位于其它窗口之 上的浮動的窗口。一個activity也可以使用附加的窗口例如, 一個在activity運(yùn)行過程中彈出的供用戶響應(yīng)的對話框,這是一個 當(dāng)用戶選擇了屏幕上特定項目后顯示的必要信息的窗口。窗口顯示的可視內(nèi)容是由一系列層次化view構(gòu)成的,這些 view均繼承自view基類。每個view均控制著窗口中一塊特定的 矩形區(qū)域。父級view包含并組織其子view的布局。葉節(jié)點(diǎn)view(位于層次結(jié)構(gòu)最底端)

6、在它們控制的矩形區(qū)域中進(jìn)行繪制,并 對用戶直達(dá)其區(qū)域的操作做出響應(yīng)。因此,view是activity與用戶 進(jìn)行交互的界面。例如,view可以顯示一個小圖片,并在用戶指 點(diǎn)它的時候產(chǎn)生動作。android有一些預(yù)置的view供開發(fā)者使用 包括按鈕、文本域、滾動條、菜單項、復(fù)選框等等。 view的層次結(jié)構(gòu)是由activity.setcontentview()方法放入 activity的窗口之中的。content view是位于層次結(jié)構(gòu)根位置的 view對象。(參見獨(dú)立的用戶界面文檔以獲取關(guān)于view及層次結(jié) 構(gòu)的更多信息。)(2) serviceservice沒有可視化的用戶界面,而是在一段時間

7、內(nèi)在后臺運(yùn) 行。例如,一個service可以在用戶做其它事情的時候在后臺播放 背景音樂、從網(wǎng)絡(luò)上獲取數(shù)據(jù)或者計算一些東西并提供給需要這 個運(yùn)算結(jié)果的activity使用。每個service都繼承自service基類。一個媒體播放器播放播放列表中的曲目是一個不錯的例子。 播放器應(yīng)用程序可能有一個或多個activity來給用戶選擇歌曲并進(jìn) 行播放。然而,音樂播放這個任務(wù)本身丌應(yīng)該由任何activity來處 理,因為用戶的期望即使在他們離開播放器的應(yīng)用程序而已經(jīng)在 開始做別的事情時,音樂仍然在繼續(xù)播放。為達(dá)到這個目的,媒 體播放器activity可以啟動一個運(yùn)行于后臺的service服務(wù)。系統(tǒng) 將在

8、這個activity不再顯示于屏幕后,仍維持音樂播放的service 的運(yùn)行。連接至(綁定到)一個正在運(yùn)行的service (如果service沒有 運(yùn)行,則啟動之)是可能的。連接之后,你可以通過那個service 暴露出來的接口不service進(jìn)行通訊。對于音樂service來說,這個 接口可以允許用戶暫停、回退、停止以及重新開始播放。如同activity和其它的組件一樣,service服務(wù)運(yùn)行于應(yīng)用程序 進(jìn)程的主線程內(nèi)。所以它不會對其它組件或者用戶界面有任何的 妨礙作用,它們一般會派生一個新線程來執(zhí)行一些時間消耗型任 務(wù)(比如音樂回放和網(wǎng)絡(luò)下載)。參見稍后的進(jìn)程和線程介紹。(3) broa

9、dcastreceiverbroadcast receiver是一個與注于接收廣播通知信息,并做出 相應(yīng)處理的組件。許多廣播是由系統(tǒng)代碼產(chǎn)生的一例如,通知 時區(qū)改變、電池電量低、拍攝了一張照片或者用戶改變了語言選 項。應(yīng)用程序也可以發(fā)起廣播一例如,通知其它應(yīng)用程序一些 數(shù)據(jù)己經(jīng)下載到設(shè)備上并處于可用狀態(tài)。一個應(yīng)用程序可以擁有任意數(shù)量的broadcast receiver,以對 所有它認(rèn)為重要的通知信息予以各種響應(yīng)。所有的receiver均繼承 自 broadcastreceiver 基類。broadcast receiver沒有用戶界面。然而,它們可以啟動一個 activity或者servic

10、e來響應(yīng)它們收到的信息,當(dāng)然也可以使用 notificationmanager來通知用戶。通知可以用多種方式來吸引用 戶的注意力閃動背光燈、震動設(shè)備、播放聲音等等。通知一 般是在狀態(tài)欄上放一個持麗的圖標(biāo),用戶可以點(diǎn)擊打開它并獲取所要消息。(4)contentprovidercontent provider將一些特定的應(yīng)用程序數(shù)據(jù)供給其它應(yīng)用程 序使用處理。數(shù)據(jù)可以存儲于文件系統(tǒng)、81數(shù)據(jù)庫或其它有 意 j 的方式。content provider 繼承于 contentprovider 基類,實 現(xiàn)了一套使得其他應(yīng)用程序能夠檢索和存儲它所管理的類型數(shù)據(jù) 的標(biāo)準(zhǔn)方法。然而,應(yīng)用程序并不直接調(diào)用返

11、些方法,而是使用 一個contentresolver對象,調(diào)用它的方法作為替代。con ten tresolver可以與任何content provider進(jìn)行會話;與其合 作對任何相關(guān)的進(jìn)程間通訊進(jìn)行管理。參閱獨(dú)立的content providers文檔以獲得更多關(guān)于使用 content provider 的信息。每當(dāng)出現(xiàn)一個需要被特定組件處理的請求時,android會確保 那個組件的應(yīng)用程序進(jìn)程處于運(yùn)行狀態(tài),必要時會啟動它,并確 保那個組件的一個合適的實例可用,必要時會創(chuàng)建那個實例。1.2激活組件:intent當(dāng)接收到 contentresolver 發(fā)出的請求后,content prov

12、ider被激活。而其它三種組件activity、service和broadcastreceiver,被一種叫做intent的異步消息所激活。intent是一個保 存著消息內(nèi)容的intent對象。對于activity和service來說,它指 明了所請求的操作名稱,并指定了用來操作的數(shù)據(jù)的uri和其它一些信息。例如,它可以承載一個對一個activity的請求,讓它為 用戶顯示一張圖片,或者讓用戶編輯一些文本。而對于broadcast receiver來說,intent對象指明了所通報的操作。例如,它可以對 所有感興趣的對象通報照相按鈕被按下。對于每種組件來說,激活的方法也是不同的:1通過傳遞一i

13、ntentcontext.start activity ()activity.startactivityforresult(以啟 動(或指定新工作給)另外一個activity。相應(yīng)的activity可以通 過調(diào)用自身的getlntent()方法來査看并且激活它的intent。 android通過調(diào)用activity的onnevintent()方法來傳遞給它隨后 的任何intent。一個activity經(jīng)常啟動另一個activity。如果它期望它所啟 動的那個activity返回一個結(jié)果,它會調(diào)用startactivityforresult() 而不是startactivity。例如,如果它啟動

14、了另外一個activity以 使用戶挑選一張自己的照片,它也許想知道哪張照片被選中了。 其結(jié)果將會被封裝在一個intent對象中,并傳遞給發(fā)出調(diào)用的 activity 的 on activity result()方法。2通過傳遞一個intent對象至context.startservice()以啟動一 個service (或向正在運(yùn)行的service給出一個新的指令)。android 調(diào)用此service的onstart()方法并將intent對象傳遞給它。與此類似,一個intent可以被傳遞給context.bindservice() 以建立一個處于調(diào)用組件和目標(biāo)service 間的活動連接

15、。此service會通過onbind()方法的調(diào)用來獲取此intent對象(如果此 service尚未運(yùn)行,bindservice會先啟動它)。例如,一個activity 可以建立一個不前述的音樂回放service的連接,這樣它就可以提 供給用戶一些途徑(用戶界面)來控制回放。這個activity可以調(diào) 用bindservice()來建立此連接,然后調(diào)用service中定之的方法來 控制回放。稍后的遠(yuǎn)程方法調(diào)用一節(jié)有關(guān)于如何綁定至一個service的更 多細(xì)節(jié)。3應(yīng)用程序可以通過傳遞一個intent對象至 context.sendbroadcast() , context. sendorder

16、edbroadcast(),以 及context.sendstickybroadcast()和其它類似方法來發(fā)起一個廣 播。android會調(diào)用所有對此廣播有興趣的broadcast receiver的 onreceive()方法,將此intent傳遞給它們。1.3關(guān)閉組件content provider僅在響應(yīng)來自contentresolver的請求時處 于不同活動狀態(tài)。而broadcast receiver僅在響應(yīng)一條廣播信息的 時候處于各種活動狀態(tài)。所以沒有必要去顯式地關(guān)閉這組件。而activity則不同,它提供了用戶界面。只要會話依然持續(xù), 無論會話過程有無空閑,activity同用戶

17、進(jìn)行長時間會話且可能一 直處于活動狀態(tài)。與此相似,service也會在很長一段時間內(nèi)在后 臺保持運(yùn)行。所以android為關(guān)閉activity和service提供了一系列有序的方法。activity可以通過調(diào)用自身的finish()方法來關(guān)閉。一個activity 可以通過調(diào)用finishactivityo方法來關(guān)閉另外一個activity (它用 startactivityforresult()啟動的)。service可以通過調(diào)用自身的stopself()方法,或調(diào)用 context.stopservice 來停止。系統(tǒng)也會在組件不再被使用的時候戒者當(dāng)android必須為更 多的活動組件回收

18、內(nèi)存時關(guān)閉它。稍后的組件的生命的周期一節(jié), 將對這種可能性及結(jié)果進(jìn)行更詳細(xì)的介紹討論。1.4 manifest 文件當(dāng)android啟動一個應(yīng)用程序組件之前,它必須知道那個組 件是存在的。因此,應(yīng)用程序會在一個被打包到android包中的 manifest文件中聲明它的組件,.apk文件還將涵括應(yīng)用程序的代 碼、文件以及其它資源。manifest文件是一個結(jié)構(gòu)化的xml文件,而且對于所有應(yīng)用 程序,文件名總是androidmanifest.xml。除了聲明此應(yīng)用程序各 個組件,它會做很多其他工作,比如指明應(yīng)用程序所需鏈接到的 庫的名稱(除了默認(rèn)的android庫外)以及標(biāo)出應(yīng)用程序期望獲 得的

19、各種權(quán)限。但manifest文件最重要的任務(wù)是向android報告此應(yīng)用程序 的各個組件。丼例說明,一個activity可能聲明如下:manifest. application. /activity/application/manifestactivity元素的name屬性指定了實現(xiàn)此activity的activity 子類。icon和丨abel屬性指向包含展示給用戶的此activity的圖標(biāo) 和標(biāo)簽的資源文件。其它組件也以類似的方法聲明元素用于聲明 service, 元素用于聲明 broadcast receiver,而 provider元素用于聲明 content provider。未在

20、manifest 文件中 進(jìn)行聲明的activity、service以及content provider將不為系統(tǒng)所 見,從而也就永不會被運(yùn)行。然而,broadcast receiver既可以在 manifest文件中聲明,也可以在代碼中動態(tài)創(chuàng)建(為 broadcastreceiver 對象),并以調(diào)用 context.registerreceiver()的 方式注冊至系統(tǒng)。1.5 intent過濾器一個intent對象可以顯式地指定一個目標(biāo)組件。如果進(jìn)行了 返種指定,android會找到這個組件(基于manifest文件中的聲 明)并激活它。但如果intent沒有顯式地指定一個目標(biāo),andr

21、oid 就必須找到最合適的組件來響應(yīng)此intent。這個過程是通過比較 intent對象和所有潛在目標(biāo)的intent過濾器完成的。組件的intent 過濾器會通知android它所能處理的intent類型。如同組件的其 它必要信息一樣,這些intent過濾器是在manifest文件中進(jìn)行聲 明的。返里有一個對先前例子的擴(kuò)展,其中加入了針對activity的 兩個intent過濾器:n=1.0 ervcoding=utf-8?manifest. application. intent-filter /application/manifest示例中的第一個過濾器action “android.in

22、tent.action.main” 和category “android丨ntent.category.launcher” 的組合是常見的一個。它標(biāo)明了此activity應(yīng)該在應(yīng)用程序啟動器中顯示, 就是用戶在屏幕上看到的此設(shè)備上可供啟動的應(yīng)用程序的列表。換句話說,這個activity是應(yīng)用程序的入口點(diǎn),是用戶在啟動器中 選擇運(yùn)行這個應(yīng)用程序后所見到的第一個activity。第二個過濾器聲明了此activity在一種特定類型的數(shù)據(jù)上可以 執(zhí)行的操作。一個組件可以擁有任意數(shù)量的intent過濾器,每個都聲明了 一套不同的功能。如果組件沒有包含任何過濾器,它只能被顯式 地指明作為目標(biāo)組件的inte

23、nt激活。對于在代碼中創(chuàng)建并注冊的broadcast receiver來說,intent 過濾器將被直接實例化intentfilter為對象。其它所有的過濾器都 在manifest文件中設(shè)置。1.6基于xml的布局雖然純粹通過java代碼在activity上創(chuàng)建和添加部件,在技 術(shù)上是可行的,我們在第4章中做的一樣,更常見的方法是使用 一種基于xml的布局文件。動態(tài)的小部件實例保留更多,情況復(fù) 雜,小工具在編譯時不為人所知(例如,在數(shù)據(jù)檢索了互聯(lián)網(wǎng)基 礎(chǔ)上將單選按鈕填充柱??紤]到這一點(diǎn),現(xiàn)在是時候打破xml來學(xué)習(xí)如何用此種方式 來布置 android activities。正如其名稱所示,一個

24、基于xml的布局是一個關(guān)系到每個規(guī) 格的小部件,和他們的容器(更多關(guān)于此內(nèi)容的在第7章)編碼 的xml格式。具體來說,android認(rèn)為基于xml的布局是資源, 因此布局的文件存儲在res/ft你的android項目布局目錄中。每個xml文件包含一個指定的部件和容器布局元素樹,一種 意見認(rèn)為構(gòu)成層次。對xml元素的屬性,描述一個部件應(yīng)如何看 或者一個容器應(yīng)如何運(yùn)轉(zhuǎn)。例如,如果一個按鈕元素。有一個android的屬性值:文字樣式=“bold”,這意味著該 文本出現(xiàn)在按鈕的表面應(yīng)該是呈現(xiàn)一個粗體字體樣式.android的sdk中附帶一個使用的布局的工具(aapt)。這個 工具應(yīng)自動調(diào)用你的andr

25、oid工具鏈(例如,eclipse中,ant s bui丨d.xml)。作為一個開發(fā)人員,尤其重要的是,在您的項目中aapt 生成r.java源文件,讓您能在那些布局中直接從java代碼中獲取 布局和部件。xml作為一個gui定義格式是越來越流行普遍。微軟的 xaml, adobe 的 flex,和 moziha 的 xul 都采取 android 類似 的方法:把布局細(xì)節(jié)放在一個xml文件和把編程智慧資料放在源 文件(例如,xul中的javascript)。許多不太知名的圖形用戶界 面框架,如zk,還使用視圖定義的xml。而“隨大流”并不一 定是最好的政策,但他們有優(yōu)勢幫助從任何其他xml為

26、中心的觀點(diǎn)描述語言輕松進(jìn)入android。1 application fundamentalsandroid applications are written in the java programming language. the compiled 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.

27、 this file is the vehicle for distributing the application and installing it on mobile devices; its the file users download to their devices. all the code in a single .apk file is considered to be one application.in many ways, each android application lives in its own world:1. by default, every appl

28、ication runs in its own linux process. android starts the process when any of the applications code needs to be executed, and shuts down the process when its no longer needed and system resources are required by other applications.2. each process has its own virtual machine (vm), so application code

29、 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 applications files are visible only to that user and only to the application itself although there are ways to export them to other applicati

30、ons as well.its possible to arrange for two applications to share the same userid, in which case they will be able to see each others files. to conserve system resources, applications with the same id can also arrange to run in the same linux process, sharing the same vm.li application componentsa c

31、entral 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 ot

32、hers, you can call upon that scroller to do the work, rather than develop your own. your application doesnt 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 s

33、tart 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 donft have a single entry point for everything in the application (no main() function, for example). rather, they have

34、 essential components that the system can instantiate and run as needed. there are four types of components:(l)activitiesan 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

35、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 activities to review old messages or change settings. though they wo

36、rk 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 activ

37、ities 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 accomplished by having the current activi

38、ty 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 pop-up dialog that calls for auser response

39、in the midst of the activity, or a window that presents users with vital information when they select a particular item on-screen.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 th

40、e 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 activitys interaction with the user takes place.for example, a

41、 view might display a small image and initiate an action when the user taps that image. android has a number of ready-made views that you can use 一 including buttons, text fields, scroll bars, menu items, check boxes, and more.a view hierarchy is placed within an activitys window by the activity.set

42、contentview() 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.)(2)servicesa service doesnt have a visual user interface, but rather runs in the background for an indefinite period of t

43、ime. for example, a service might play background music as the user attends to other matters, or itmight fetch data over the network or calculate something and provide the result to activities thcu need it. each service extends the service base class.a prime example is a media player playing songs f

44、rom 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 a

45、nd begin something different. to keep the music going, the media player activity could start a service to mn in the background. the system would then keep the music playback service running even after the activity that started it leaves the screen.its possible to connect to (bind to) an ongoing serv

46、ice (and start the service if its not already running). while connected, you can communicate with the service through an interface that the service exposes. for the music service, this interface might allow users to pause, rewind, stop, and restart the playback.like activities and the other componen

47、ts, services run in the main thread of the application process. so that they wont block other components or the user interface, they often spawn another thread for time-consuming tasks (like music playback). see processes and threads, later.(3) broadcast receiversa broadcast receiver is a component

48、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 initiat

49、e 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 ba

50、se 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 users attention in various ways flashing the backlight, vibrating the de

51、vice, playing a sound, and so on. they typically place a persistent icon in the status bar, which users can open to get the message.(4) content providersa content provider makes a specific set of the applications data available to other applications. the data can be stored in the filesystem, in an s

52、qlite 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. rat

53、her they use a contentresolver object and call its methods instead. a contentresolver can talk to any content provider; it cooperates with the provider to manage any interprocess communication thats involved.see the separate content providers document for more information on using content providers.

54、whenever theres a request that should be handled by a particular component, android makes sure that the application process of the component is running, starting it if necessary, and that an appropriate instance of the component is available, creating the instance ifnecessary.1.2 activating componen

55、ts: intentscontent providers are activated when theyre targeted by a requestfrom a contentresolver. the other three components 一 activities.services, and broadcast receivers are activated by asynchronousmessages called intents. an intent is an intent object that holds the content of the message. for

56、 activities and services, it names the actionbeing 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 component:1. an activity is launched (or given something new to

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論