【正文】
ller to do the work, rather than develop your own. Your application doesn39。s code needs to be executed, and shuts down the process when it39。長春理工大學(xué)光電信息學(xué)院畢業(yè)設(shè)計 1 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。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。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。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。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 長春理工大學(xué)光電信息學(xué)院畢業(yè)設(shè)計 4 message. Content providers A content provider makes a specific set of the application39。s a request that should be handled 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 passed to the calling activity39。s responding to a broadcast message. So there39。s code, files, and resources. The manifest is a structured XML file and is always named for all applications. It does a number of things in addition to declaring the application39。re declared in the manifest file. Here39。 aapt 工具把編譯后的 Java 代碼連同應(yīng)用程序所需的其他數(shù)據(jù)和資源文件一起打包到一個 Android 包文件中,這個文件使用 .apk作為擴(kuò)展名。當(dāng)應(yīng)用程序中的任何代碼需 要被執(zhí)行時, Android 啟動此進(jìn)程,而當(dāng)不再需要此進(jìn)程并且其它應(yīng)用程序又請求系統(tǒng)資源時,則關(guān)閉這個進(jìn)程。例如,如果你的應(yīng)用程序需要顯示一個圖片卷動列表,而另一個應(yīng)用程序已經(jīng)開發(fā)了一個合用的而又允許別的應(yīng)用程序使用的話,你可以直接調(diào)用那個卷動列表來完成工作,而不用自己再開發(fā)一個。因此,不像其它大多數(shù)系統(tǒng)上的應(yīng)用程序, Android 應(yīng)用程序并沒有為應(yīng)用程序提供一個單獨的入口點 (比如說,沒有 main()函數(shù)),而是為系統(tǒng)提供了可以實例化和運行所需的必備組件。盡管它們一起組成了一個內(nèi)聚的用戶界面,但其中每個 activity都不其它的保持獨立。一般情況下,總有一個應(yīng)用程序被標(biāo)記為用戶在應(yīng)用程序啟動的時候第一個看到的。一個 activity也可以使用附加窗口 ——例如,一個在 activity運行過程中彈出的供用戶響應(yīng)的對話框,戒是一個當(dāng)用戶選擇了屏幕上特定項目后顯示的必要信息的窗口。葉節(jié)點 view(位于層次結(jié)構(gòu)最底端)在它們控制的矩形區(qū)域中進(jìn)行繪制,并對用戶直達(dá)其區(qū)域的操作做出響應(yīng)。 view 層次結(jié)構(gòu)是由 () 方法放入 activity的窗口之中的。例如,一 個service 可以在用戶做其它事情的時候在后臺播放背景音樂、從網(wǎng)絡(luò)上獲取數(shù)據(jù)或者計算一些東西并提供給需要這個運算結(jié)果的 activity使用。然而,音樂播放這個任務(wù)本身丌應(yīng)該由任何 activity來處理,因為用戶期望即使在他們離開播放器應(yīng)用程序而開始做別的事情時,音樂仍在繼續(xù)播放。連接之后,你可以通過那個 service 暴露出來的接口不 service 進(jìn)行通訊。參見稍后的進(jìn)程和線程。 一個應(yīng)用程序可以擁有任意數(shù)量的 broadcast receiver,以對所有它認(rèn)為重要的通知信息予以響應(yīng)。通知可以用多種方式來吸引用戶的注意力──閃動背光燈、震動設(shè)備、播放聲音等等。 content provider 繼承于ContentProvider 基類,實現(xiàn)了一套使得其他應(yīng)用程序能夠檢索和存儲它所管理的類型數(shù)據(jù)的標(biāo)準(zhǔn)方法。 每當(dāng)出現(xiàn)一個需要被特定組件處理的請求時, Android 會確保那個組件的應(yīng)用程序進(jìn)程處于運行狀態(tài),必要時會啟動它,并確保那個組件的一個合適的實例可用,必要時會創(chuàng)建那個實例。 對于 activity和 service 來說,它指明了所請求的操作名稱,并指定了用來操作的數(shù)據(jù)的 URI 和其它一些信息。 對于每種組件來說,激活的方法是不同的: 1 通過傳遞一()(以啟動(或指定新工作給)一個 activity。如果它期望它所啟動的那個 activity迒回一個結(jié)果,它會調(diào)用 startActivityForResult()而不是 startActivity()。 Android 調(diào)用此 service 的 onStart()方法并將Intent 對象傳遞給它。這個 activity可以調(diào)用 bindService()來建立此連接,然后調(diào)用 service 中定之的方法來控制回放。 關(guān)閉組件 content provider 僅在響應(yīng)來自 ContentResolver 的請求時處于活動狀態(tài)