版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、<p> 附錄一:英文翻譯原文 </p><p><b> Abstract</b></p><p> With the development of the mobile phone market,3G mobile phone system development has also become popular on the maket. This
2、 paper introduces some basic applications of the Android system about a part of the Application Fundamentas book translation, so that more learners can easily learn about the development and application of the Android sy
3、stem. Translation about this paper is my personal understanding of the Application Fundaments, there are some similarities and differences with the origina</p><p> Key word: application components, closed c
4、omponents , Intent filter, manifest files, activity, Service, Broadcast receiver , Content provider</p><p> Android applications are written in the Java programming language. The compiled Java code — along
5、 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
6、 installing it on mobile devices; it's the file users download to their devices. All the code in a single .apk file is considered to be one application.</p><p> In many ways, each Android application li
7、ves in its own world:</p><p> 1. By default, every application runs in its own Linux process. Android starts the process when any of the application's code needs to be executed, and shuts down the proce
8、ss when it's no longer needed and system resources are required by other applications.</p><p> 2. Each process has its own virtual machine (VM), so application code runs in isolation from the code of al
9、l other applications.</p><p> 3. By default, each application is assigned a unique Linux user ID. Permissions are set so that the application's files are visible only to that user and only to the applic
10、ation itself — although there are ways to export them to other applications as well.</p><p> It's possible to arrange for two applications to share the same user ID, in which case they will be able to s
11、ee each other'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.</p><p> Application Components</p><p
12、> 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 ima
13、ges 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 doesn't incorporate the co
14、de of the other application or link to it. Rather, it simply starts up</p><p> For this to work, the system must be able to start an application process when any part of it is needed, and instantiate the Ja
15、va objects for that part. Therefore, unlike applications on most other systems, Android applications don't have a single entry point for everything in the application (no main() function, for example). Rather, they h
16、ave essential components that the system can instantiate and run as needed. There are four types of components:</p><p> Activities</p><p> An activity presents a visual user interface for one
17、focused endeavor the user can undertake. For </p><p> example, an activity might present a list of menu items users can choose from or it might display </p><p> Photographs along with their ca
18、ptions. 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
19、 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.</p><p> An applic
20、ation 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 desi
21、gn. 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 activity st
22、art the next one.</p><p> 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 c
23、an also make use of additional windows — for example, a pop-up 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
24、 on-screen.</p><p> 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. Pare
25、nt 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
26、the activity's interaction with the user takes place.</p><p> For example, a view might display a small image and initiate an action when the user taps that image. Android has a number of ready-made vie
27、ws that you can use — including buttons, text fields, scroll bars, menu items, check boxes, and more.</p><p> A view hierarchy is placed within an activity's window by the Activity.setContentView() meth
28、od. 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.)</p><p><b> Services</b></p>
29、;<p> A service doesn'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 matter
30、s, or it might fetch data over the network or calculate something and provide the result to activities that need it. Each service extends the Service base class.</p><p> A prime example is a media player pl
31、aying 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 ac
32、tivity 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
33、. The system would then </p><p> It's possible to connect to (bind to) an ongoing service (and start the service if it's not already running). While connected, you can communicate with the service t
34、hrough an interface that the service exposes. For the music service, this interface might allow users to pause, rewind, stop, and restart the playback.</p><p> Like activities and the other components, serv
35、ices run in the main thread of the application process. So that they won't block other components or the user interface, they often spawn another thread for time-consuming tasks (like music playback). See Processes a
36、nd Threads, later.</p><p> Broadcast receivers</p><p> A broadcast receiver is a component that does nothing but receive and react to broadcast announcements. Many broadcasts originate in syst
37、em 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
38、example, to let other applications know that some data has been downloaded to the device and is available for them to use.</p><p> An application can have any number of broadcast receivers to respond to any
39、 announcements it considers important. All receivers extend the BroadcastReceiver base class.</p><p> Broadcast receivers do not display a user interface. However, they may start an activity in response to
40、the information they receive, or they may use the NotificationManager to alert the user. Notifications can get the user's attention in various ways — flashing the backlight, vibrating the device, playing a sound, and
41、 so on. They typically place a persistent icon in the status bar, which users can open to get the message.</p><p> Content providers</p><p> A content provider makes a specific set of the appl
42、ication'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 t
43、o 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
44、and call its </p><p> See the separate Content Providers document for more information on using content providers.</p><p> Whenever there's a request that should be handled by a particular
45、 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 if necessary.</p
46、><p> Activating components: intents</p><p> Content providers are activated when they're targeted by a request from a ContentResolver. The other three components — activities, services, and
47、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 speci
48、fies 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 </p><p> There are separate methods for activating each type of componen
49、t:</p><p> 1. An activity is launched (or given something new to do) by passing an Intent object to</p><p> Context.startActivity() or Activity.startActivityForResult(). The responding activit
50、y can look at the initial intent that caused it to be launched by calling its getIntent() method. Android calls the activity's onNewIntent() method to pass it any subsequent intents. One activity often starts the ne
51、xt one. If it expects a result back from the activity it's starting, it calls startActivityForResult() instead of startActivity(). For example, if it starts an activity that lets the user pick a pho</p><
52、p> 2. A service is started (or new instructions are given to an ongoing service) by passing an Intent object to Context.startService(). Android calls the service's onStart() method and passes it the Intent object
53、. Similarly, an intent can be passed to Context.bindService() to establish an ongoing connection between the calling component and a target service. The service receives the Intent object in an onBind() call. (If the ser
54、vice is not already running, bindService() can optionally start it.) Fo</p><p> A later section, Remote procedure calls, has more details about binding to a service.</p><p> 3. An application
55、can initiate a broadcast by passing an Intent object to methods like Context.sendBroadcast(), Context.sendOrderedBroadcast(), and Context.sendStickyBroadcast() in any of their variations.</p><p> Android de
56、livers the intent to all interested broadcast receivers by calling their onReceive() methods. For more on intent messages, see the separate article, Intents and Intent Filters.</p><p> Shutting down compone
57、nts</p><p> A content provider is active only while it's responding to a request from a ContentResolver. And a broadcast receiver is active only while it's responding to a broadcast message. So ther
58、e's no need to explicitly shut down these components.</p><p> Activities, on the other hand, provide the user interface. They're in a long-running conversation with the user and may remain active, e
59、ven when idle, as long as the conversation continues. Similarly, services may also remain running for a long time. So Android has methods to shut down activities and services in an orderly way: Context.stopService().<
60、/p><p> Components might also be shut down by the system when they are no longer being used or when Android must reclaim memory for more active components. A later section, Component Lifecycles, discusses this
61、 possibility and its ramifications in more detail.</p><p> The manifest file</p><p> Before Android can start an application component, it must learn that the component exists. Therefore, appl
62、ications declare their components in a manifest file that's bundled into the Android package, the .apk file that also holds the application's code, files, and resources.</p><p> The manifest is a st
63、ructured XML file and is always named AndroidManifest.xml for all applications. It does a number of things in addition to declaring the application's components, such as naming any libraries the application needs to
64、be linked against (besides the default Android library) and identifying any permissions the application expects to be granted.</p><p> But the principal task of the manifest is to inform Android about the a
65、pplication's components. For example, an activity might be declared as follows:</p><p> Figure 1 the struck of Activity</p><p> The name attribute of the <activity> element names the
66、 Activity subclass that implements the activity. The icon and label attributes point to resource files containing an icon and label that can be displayed to users to represent the activity.</p><p> The othe
67、r components are declared in a similar way — <service> elements for services, <receiver> elements for broadcast receivers, and <provider> elements for content providers. Activities, services, and conten
68、t providers that are not declared in the manifest are not visible to the system and are consequently never run. However, broadcast receivers can either be declared in the manifest, or they can be created dynamically in c
69、ode (as BroadcastReceiver objects) and registered with the system by c</p><p> For more on how to structure a manifest file for your application, see The Android Manifest.xml File.</p><p> Int
70、ent filters</p><p> An Intent object can explicitly name a target component. If it does, Android finds that component (based on the declarations in the manifest file) and activates it. But if a target is no
71、t explicitly named, Android must locate the best component to respond to the intent. It does so by comparing the Intent object to the intent filters of potential targets. A component's intent filters inform Android o
72、f the kinds of intents the component is able to handle. Like other essential information about the</p><p> Figure 2 the struck of the Intent</p><p> The first filter in the example — the combi
73、nation of the action "android.intent.action.MAIN" and the category "android.intent.category.LAUNCHER" — is a common one. It marks the activity as one that should be represented in the application laun
74、cher, 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.
75、</p><p> The second filter declares an action that the activity can perform on a particular type of data.</p><p> A component can have any number of intent filters, each one declaring a differ
76、ent set of capabilities. If it doesn't have any filters, it can be activated only by intents that explicitly name the component as the target.</p><p> For a broadcast receiver that's created and reg
77、istered in code, the intent filter is instantiated directly as an Intent Filter object. All other filters are set up in the manifest.</p><p> For more on intent filters, see a separate document, Intents and
78、 Intent Filters.</p><p> 附錄二:英文翻譯譯文</p><p><b> 摘要</b></p><p> 隨著手機市場的發(fā)展,3G手機逐漸占領手機市場,3G手機系統(tǒng)開發(fā)也成為市場上的熱門技術。本論文主要介紹android系統(tǒng)的一些基本應用程序,是對Application Fundamentals這本書的部分翻譯,
79、讓更多的學習者可以輕松的學習了解android系統(tǒng)的開發(fā)和應用。論文中的翻譯內(nèi)容是本人對Application Fundamentals的個人理解,與原著存在一些異同,想了解更多關于或更詳細android系統(tǒng)應用基礎可以參考本文閱讀原著,本文只對android系統(tǒng)應用基礎中的應用組件、關閉組件、manifest文件、Intent過濾器進行簡單的描述介紹。</p><p> 關鍵字:應用組件、關閉組件、manif
80、est文件、Intent過濾器、activity、Service、Broadcast receiver、Content provider</p><p> Android應用程序使用Java編程語言開發(fā)。aapt工具把編譯后的Java代碼連同應用程序所需的其他數(shù)據(jù)和資源文件一起打包到一個Android包文件中,這個文件使用.apk作為擴展名。此文件是分發(fā)并安裝應用程序到移動設備的載體;是用戶下載到他們的設備的文
81、件。單一.apk文件中的所有代碼被認為是一個應用程序。</p><p> 從多個角度來看,每個Android應用程序都存在于它自己的世界之中:</p><p> 1 默認情況下,每個應用程序均運行于它自己的Linux進程中。當應用程序中的任何代碼需要被執(zhí)行時,Android啟動此進程,而當不再需要此進程并且其它應用程序又請求系統(tǒng)資源時,則關閉這個進程。 </p><
82、p> 2 每個進程都有其獨有的虛擬機(VM),所以應用程序代碼與所有其它應用程序代碼是隔離運行的。 </p><p> 3 默認情況下,每個應用程序均被賦予一個唯一的Linux用戶ID,并加以權限設置,使得應用程序的文件僅對此用戶及此應用程序可見——盡管也有其它的方法使得這些文件同樣能為其他應用程序所訪問。 </p><p><b> 1 應用程序組件</b&g
83、t;</p><p> Android的一個核心特性就是一個應用程序可以使用其它應用程序的元素(如果那個應用程序允許的話)。例如,如果你的應用程序需要顯示一個圖片卷動列表,而另一個應用程序已經(jīng)開發(fā)了一個合用的而又允許別的應用程序使用的話,你可以直接調(diào)用那個卷動列表來完成工作,而不用自己再開發(fā)一個。你的應用程序并沒有吸納或鏈接其它應用程序的代碼。它只是在有需求的時候啟動了其它應用程序的那個功能部分。 為達到這個目
84、的,系統(tǒng)必須能夠在一個應用程序的任何一部分被需要時啟動一個此應用程序的進程,并將那個部分的Java對象實例化。因此,不像其它大多數(shù)系統(tǒng)上的應用程序,Android應用程序并沒有為應用程序提供一個單獨的入口點(比如說,沒有main()函數(shù)),而是為系統(tǒng)提供了可以實例化和運行所需的必備組件。一共有四種組件類型: </p><p> 1 Activity </p><p> activity
85、是為用戶操作而展示的可視化用戶界面。例如,一個activity可以展示一個菜單項列表供用戶選擇,戒者顯示一些包含說明文字的照片。一個短消息應用程序可以包括一個用于顯示要發(fā)送消息到的聯(lián)系人列表的activity,一個給選定的聯(lián)系人寫短信的activity。以及翻閱以前的短信或改變設置的其他activity。盡管它們一起組成了一個內(nèi)聚的用戶界面,但其中每個activity都不其它的保持獨立。每一個都實現(xiàn)為以Activity類為基類的子類。
86、</p><p> 一個應用程序可以只有一個activity,戒者,如剛才提到的短信應用程序那樣,包含很多個。每個activity的作用,以及有多少個activity,當然是取決于應用程序及其設計的。一般情況下,總有一個應用程序被標記為用戶在應用程序啟動的時候第一個看到的。從一個activity轉(zhuǎn)向另一個靠的是用當前的activity啟動下一個。 </p><p> 每個activit
87、y都被給予一個默認的窗口以進行繪制。一般情況下,這個窗口是滿屏的,但它也可以是一個小的位于其它窗口之上的浮動窗口。一個activity也可以使用附加窗口——例如,一個在activity運行過程中彈出的供用戶響應的對話框,戒是一個當用戶選擇了屏幕上特定項目后顯示的必要信息的窗口。 </p><p> 窗口顯示的可視內(nèi)容是由一系列層次化view構成的,這些view均繼承自 View 基類。每個view均控制著窗口中
88、一塊特定的矩形區(qū)域。父級view包含并組織其子view的布局。葉節(jié)點view(位于層次結(jié)構最底端)在它們控制的矩形區(qū)域中進行繪制,并對用戶直達其區(qū)域的操作做出響應。因此,view是activity與用戶進行交互的界面。例如,view可以顯示一個小圖片,并在用戶指點它的時候產(chǎn)生動作。Android有一些預置的view供開發(fā)者使用——包括按鈕、文本域、滾動條、菜單項、復選框等等。 </p><p> view層次結(jié)
89、構是由Activity.setContentView() 方法放入activity的窗口之中的。content view是位于層次結(jié)構根位置的View對象。(參見獨立的用戶界面文檔以獲取關于view及層次結(jié)構的更多信息。) </p><p> 2 Service </p><p> service沒有可視化的用戶界面,而是在一段時間內(nèi)在后臺運行。例如,一個service可以在用戶做其它
90、事情的時候在后臺播放背景音樂、從網(wǎng)絡上獲取數(shù)據(jù)或者計算一些東西并提供給需要這個運算結(jié)果的activity使用。每個service都繼承自Service基類。 </p><p> 一個媒體播放器播放播放列表中的曲目是一個不錯的例子。播放器應用程序可能有一個或多個activity來給用戶選擇歌曲并進行播放。然而,音樂播放這個任務本身丌應該由任何activity來處理,因為用戶期望即使在他們離開播放器應用程序而開始做
91、別的事情時,音樂仍在繼續(xù)播放。為達到這個目的,媒體播放器activity可以啟動一個運行于后臺的service。系統(tǒng)將在這個activity不再顯示于屏幕乀后,仍維持音樂播放service的運行。 </p><p> 連接至(綁定到)一個正在運行的service(如果service沒有運行,則啟動之)是可能的。連接之后,你可以通過那個service暴露出來的接口不service進行通訊。對于音樂service來
92、說,這個接口可以允許用戶暫停、回退、停止以及重新開始播放。 </p><p> 如同activity和其它組件一樣,service運行于應用程序進程的主線程內(nèi)。所以它不會對其它組件或用戶界面有任何妨礙,它們一般會派生一個新線程來執(zhí)行一些時間消耗型任務(比如音樂回放)。參見稍后的進程和線程。 </p><p> 3 Broadcast receiver </p><p
93、> broadcast receiver是一個與注于接收廣播通知信息,并做出相應處理的組件。許多廣播是由系統(tǒng)代碼產(chǎn)生的——例如,通知時區(qū)改變、電池電量低、拍攝了一張照片或者用戶改變了語言選項。應用程序也可以發(fā)起廣播——例如,通知其它應用程序一些數(shù)據(jù)已經(jīng)下載到設備上并處于可用狀態(tài)。 </p><p> 一個應用程序可以擁有任意數(shù)量的broadcast receiver,以對所有它認為重要的通知信息予以響應
94、。所有的receiver均繼承自BroadcastReceiver基類。 </p><p> broadcast receiver沒有用戶界面。然而,它們可以啟動一個activity來響應它們收到的信息,或者也可以使用NotificationManager來通知用戶。通知可以用多種方式來吸引用戶的注意力──閃動背光燈、震動設備、播放聲音等等。通知一般是在狀態(tài)欄上放一個持麗的圖標,用戶可以打開它并獲取消息。 &l
95、t;/p><p> 4 Content provider </p><p> content provider將一些特定的應用程序數(shù)據(jù)供給其它應用程序使用。數(shù)據(jù)可以存儲于文件系統(tǒng)、SQLite數(shù)據(jù)庫或其它有意丿的方式。content provider繼承于ContentProvider 基類,實現(xiàn)了一套使得其他應用程序能夠檢索和存儲它所管理的類型數(shù)據(jù)的標準方法。然而,應用程序并不直接調(diào)用返
96、些方法,而是使用一個 ContentResolver 對象,調(diào)用它的方法作為替代。ContentResolver可以與任何content provider進行會話;與其合作對任何相關的進程間通訊進行管理。 </p><p> 參閱獨立的Content Providers文檔以獲得更多關于使用content provider的信息。 </p><p> 每當出現(xiàn)一個需要被特定組件處理的請
97、求時,Android會確保那個組件的應用程序進程處于運行狀態(tài),必要時會啟動它,并確保那個組件的一個合適的實例可用,必要時會創(chuàng)建那個實例。 </p><p> 1.1激活組件:intent</p><p> 當接收到ContentResolver發(fā)出的請求后,content provider被激活。而其它三種組件——activity、service和broadcast receiver,
98、被一種叫做intent的異步消息所激活。intent是一個保存著消息內(nèi)容的Intent對象。對于activity和service來說,它指明了所請求的操作名稱,并指定了用來操作的數(shù)據(jù)的URI和其它一些信息。例如,它可以承載一個對一個activity的請求,讓它為用戶顯示一張圖片,或者讓用戶編輯一些文本。而對于broadcast receiver來說,Intent對象指明了所通報的操作。例如,它可以對所有感興趣的對象通報照相按鈕被按下。
99、對于每種組件來說,激活的方法是不同的: </p><p> 1 通過傳遞一IntentContext.startActivity()Activity.startActivityForResult(以啟動(或指定新工作給)一個activity。相應的activity可以通過調(diào)用自身的 getIntent() 方法來查看最刜激活它的intent。Android通過調(diào)用activity的onNewIntent()方法
100、來傳遞給它隨后的任何intent。</p><p> 一個activity經(jīng)常啟動另一個activity。如果它期望它所啟動的那個activity迒回一個結(jié)果,它會調(diào)用startActivityForResult()而不是startActivity()。例如,如果它啟動了另外一個activity以使用戶挑選一張照片,它也許想知道哪張照片被選中了。其結(jié)果將會被封裝在一個Intent對象中,并傳遞給發(fā)出調(diào)用的act
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- android系統(tǒng)外文翻譯3
- android起航外文翻譯
- android應用架構外文翻譯
- android手機外文翻譯---應用程序基礎android developers
- 外文翻譯---深入理解android系統(tǒng)安全性
- android畢業(yè)設計外文資料翻譯
- 實現(xiàn)android手機音樂應用-外文翻譯
- android起航畢業(yè)論文外文翻譯
- 外文翻譯---應用程序基礎android developers
- android外文翻譯--外文翻譯--在安卓平臺的擊鍵動力學
- android外文翻譯--外文翻譯--在安卓平臺的擊鍵動力學
- android點菜軟件外文翻譯--基于安卓系統(tǒng)的電子菜單軟件
- 外文翻譯基于android操作系統(tǒng)的座位管理系統(tǒng)的研究和實現(xiàn)
- android外文翻譯--深入理解安卓系統(tǒng)的安全性
- 外文翻譯-基于android平臺的餐飲管理系統(tǒng)的設計與實現(xiàn)
- android點菜軟件外文翻譯--基于安卓系統(tǒng)的電子菜單軟件
- android點菜軟件外文翻譯--基于安卓系統(tǒng)的電子菜單軟件
- 基于Android系統(tǒng)的閱讀器設計與實現(xiàn)外文翻譯.doc
- 外文翻譯基于android操作系統(tǒng)的座位管理系統(tǒng)的研究和實現(xiàn)
- android外文翻譯--外文翻譯--在安卓平臺的擊鍵動力學
評論
0/150
提交評論