版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、<p><b> 英文原文及譯文</b></p><p> Application Fundamentals</p><p> Android applications are written in the Java programming language. The compiled Java code — along with any data a
2、nd 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 o
3、n 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 lives in its own w
4、orld:</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 process when it's
5、 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 all other applicat
6、ions.</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 application itself — a
7、lthough 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 see each other
8、9;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> A central
9、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
10、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 code of the other
11、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 Java objects for t
12、hat 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 have essential co
13、mponents 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 focused endeavor
14、 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 t
15、hat 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 work together to form a</p>
16、;<p> 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 a
17、pplication 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
18、the current activity start 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
19、 windows. An activity can 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 s
20、elect a particular item 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
21、within the 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.
22、 Thus, views are where 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 n
23、umber of ready-made views 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 Activit
24、y.setContentView() 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.)</p><p><b> Serv
25、ices</b></p><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
26、attends to other matters, 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 examp
27、le 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
28、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 t
29、o run in the background. 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 communi
30、cate 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.</p><p> Like activities and the
31、 other components, services 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 pla
32、yback). See Processes and 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 broad
33、casts 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 ini
34、tiate broadcasts — for 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 rece
35、ivers to respond to any 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 a
36、ctivity in response to 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 devic
37、e, playing a sound, and 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 s
38、pecific set of the application'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 Conte
39、ntProvider 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. Rather they use a
40、ContentResolver object 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
41、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 insta
42、nce if necessary.</p><p> Activating components: intents</p><p> Content providers are activated when they're targeted by a request from a ContentResolver. The other three components — act
43、ivities, services, and 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 be
44、ing 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 </p><p> Intent object names the action being ann
45、ounced. For example, it might announce to interested parties that the camera button has been pressed.</p><p> There are separate methods for activating each type of component:</p><p> 1. An ac
46、tivity is launched (or given something new to do) by passing an Intent object to</p><p> Context.startActivity() or Activity.startActivityForResult(). The responding activity can look at the initial intent
47、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 next one. If it expects a result ba
48、ck 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><p> 2. A service is started (o
49、r 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. Similarly, an intent can be pas
50、sed 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 service is not already running, bind
51、Service() 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 can initiate a broadcast by passi
52、ng an Intent object to methods like Context.sendBroadcast(), Context.sendOrderedBroadcast(), and Context.sendStickyBroadcast() in any of their variations.</p><p> Android delivers the intent to all interest
53、ed broadcast receivers by calling their onReceive() methods. For more on intent messages, see the separate article, Intents and Intent Filters.</p><p> Shutting down components</p><p> A conte
54、nt 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 there's no need to explicitly shu
55、t 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, even when idle, as long as the con
56、versation 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:</p><p> 1. An activity can be shut down by ca
57、lling its finish() method. One activity can shut down another activity (one it started with startActivityForResult()) by calling finishActivity().</p><p> 2. A service can be stopped by calling its stopSelf
58、() method, or by calling Context.stopService().</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
59、later section, Component Lifecycles, discusses this possibility and its ramifications in more detail.</p><p> The manifest file</p><p> Before Android can start an application component, it mu
60、st learn that the component exists. Therefore, applications 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 re
61、sources.</p><p> The manifest is a structured 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, suc
62、h as naming any libraries the application needs to be linked against (besides the default Android library) and identifying any permissions the application expects to be granted.</p><p> But the principal ta
63、sk of the manifest is to inform Android about the application's components. For example, an activity might be declared as follows:</p><p> The name attribute of the <activity> element names the Ac
64、tivity 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 other c
65、omponents are declared in a similar way — <service> elements for services, <receiver> elements for broadcast receivers, and <provider> elements for content providers. Activities, services, and content p
66、roviders 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 code
67、 (as BroadcastReceiver objects)and registered with the system by ca</p><p> For more on how to structure a manifest file for your application, see The Android Manifest.xml File.</p><p> Intent
68、 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 not e
69、xplicitly 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 of t
70、he kinds of intents the component is able to handle. Like other essential information about the</p><p> The first filter in the example — the combination of the action "android.intent.action.MAIN"
71、 and the category</p><p> "android.intent.category.LAUNCHER" — is a common one. It marks the activity as one that should be represented in the application launcher, the screen listing applications
72、 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.</p><p> The second fil
73、ter 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 different set of capabilities. If it doesn&
74、#39;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 registered in code, the intent filter is
75、 instantiated directly as an IntentFilter object. All other filters are set up in the manifest.</p><p> For more on intent filters, see a separate document, Intents and Intent Filters.</p><p>
76、 應(yīng)用程序基礎(chǔ)Android Developers</p><p> Android應(yīng)用程序使用Java編程語(yǔ)言開(kāi)發(fā)。aapt工具把編譯后的Java代碼連同應(yīng)用程序所需的其他數(shù)據(jù)和資源文件一起打包到一個(gè)Android包文件中,這個(gè)文件使用.apk作為擴(kuò)展名。此文件是分發(fā)并安裝應(yīng)用程序到移動(dòng)設(shè)備的載體;是用戶(hù)下載到他們的設(shè)備的文件。單一.apk文件中的所有代碼被認(rèn)為是一個(gè)應(yīng)用程序。</p><
77、p> 從多個(gè)角度來(lái)看,每個(gè)Android應(yīng)用程序都存在于它自己的世界之中:</p><p> 1 默認(rèn)情況下,每個(gè)應(yīng)用程序均運(yùn)行于它自己的Linux進(jìn)程中。當(dāng)應(yīng)用程序中的任何代碼需要被執(zhí)行時(shí),Android啟動(dòng)此進(jìn)程,而當(dāng)不再需要此進(jìn)程并且其它應(yīng)用程序又請(qǐng)求系統(tǒng)資源時(shí),則關(guān)閉這個(gè)進(jìn)程。 </p><p> 2 每個(gè)進(jìn)程都有其獨(dú)有的虛擬機(jī)(VM),所以應(yīng)用程序代碼與所有其它應(yīng)用程
78、序代碼是隔離運(yùn)行的。 </p><p> 3 默認(rèn)情況下,每個(gè)應(yīng)用程序均被賦予一個(gè)唯一的Linux用戶(hù)ID,并加以權(quán)限設(shè)置,使得應(yīng)用程序的文件僅對(duì)此用戶(hù)及此應(yīng)用程序可見(jiàn)——盡管也有其它的方法使得這些文件同樣能為其他應(yīng)用程序所訪問(wèn)。 </p><p><b> 1 應(yīng)用程序組件</b></p><p> Android的一個(gè)核心特性就是一個(gè)
79、應(yīng)用程序可以使用其它應(yīng)用程序的元素(如果那個(gè)應(yīng)用程序允許的話(huà))。例如,如果你的應(yīng)用程序需要顯示一個(gè)圖片卷動(dòng)列表,而另一個(gè)應(yīng)用程序已經(jīng)開(kāi)發(fā)了一個(gè)合用的而又允許別的應(yīng)用程序使用的話(huà),你可以直接調(diào)用那個(gè)卷動(dòng)列表來(lái)完成工作,而不用自己再開(kāi)發(fā)一個(gè)。你的應(yīng)用程序并沒(méi)有吸納或鏈接其它應(yīng)用程序的代碼。它只是在有需求的時(shí)候啟動(dòng)了其它應(yīng)用程序的那個(gè)功能部分。 </p><p> 為達(dá)到這個(gè)目的,系統(tǒng)必須能夠在一個(gè)應(yīng)用程序的任何一部
80、分被需要時(shí)啟動(dòng)一個(gè)此應(yīng)用程序的進(jìn)程,并將那個(gè)部分的Java對(duì)象實(shí)例化。因此,不像其它大多數(shù)系統(tǒng)上的應(yīng)用程序,Android應(yīng)用程序并沒(méi)有為應(yīng)用程序提供一個(gè)單獨(dú)的入口點(diǎn)(比如說(shuō),沒(méi)有main()函數(shù)),而是為系統(tǒng)提供了可以實(shí)例化和運(yùn)行所需的必備組件。一共有四種組件類(lèi)型: </p><p> 1 Activity</p><p> activity是為用戶(hù)操作而展示的可視化用戶(hù)界面。例如,
81、一個(gè)activity可以展示一個(gè)菜單項(xiàng)列表供用戶(hù)選擇,戒者顯示一些包含說(shuō)明文字的照片。一個(gè)短消息應(yīng)用程序可以包括一個(gè)用于顯示要發(fā)送消息到的聯(lián)系人列表的activity,一個(gè)給選定的聯(lián)系人寫(xiě)短信的activity以及翻閱以前的短信或改變?cè)O(shè)置的其他activity。盡管它們一起組成了一個(gè)內(nèi)聚的用戶(hù)界面,但其中每個(gè)activity都不其它的保持獨(dú)立。每一個(gè)都實(shí)現(xiàn)為以Activity類(lèi)為基類(lèi)的子類(lèi)。 </p><p>
82、 一個(gè)應(yīng)用程序可以只有一個(gè)activity,戒者,如剛才提到的短信應(yīng)用程序那樣,包含很多個(gè)。每個(gè)activity的作用,以及有多少個(gè)activity,當(dāng)然是取決于應(yīng)用程序及其設(shè)計(jì)的。一般情況下,總有一個(gè)應(yīng)用程序被標(biāo)記為用戶(hù)在應(yīng)用程序啟動(dòng)的時(shí)候第一個(gè)看到的。從一個(gè)activity轉(zhuǎn)向另一個(gè)靠的是用當(dāng)前的activity啟動(dòng)下一個(gè)。 </p><p> 每個(gè)activity都被給予一個(gè)默認(rèn)的窗口以進(jìn)行繪制。一般情況
83、下,這個(gè)窗口是滿(mǎn)屏的,但它也可以是一個(gè)小的位于其它窗口之上的浮動(dòng)窗口。一個(gè)activity也可以使用附加窗口——例如,一個(gè)在activity運(yùn)行過(guò)程中彈出的供用戶(hù)響應(yīng)的對(duì)話(huà)框,戒是一個(gè)當(dāng)用戶(hù)選擇了屏幕上特定項(xiàng)目后顯示的必要信息的窗口。 </p><p> 窗口顯示的可視內(nèi)容是由一系列層次化view構(gòu)成的,這些view均繼承自 View 基類(lèi)。每個(gè)view均控制著窗口中一塊特定的矩形區(qū)域。父級(jí)view包含并組織其
84、子view的布局。葉節(jié)點(diǎn)view(位于層次結(jié)構(gòu)最底端)在它們控制的矩形區(qū)域中進(jìn)行繪制,并對(duì)用戶(hù)直達(dá)其區(qū)域的操作做出響應(yīng)。因此,view是activity與用戶(hù)進(jìn)行交互的界面。例如,view可以顯示一個(gè)小圖片,并在用戶(hù)指點(diǎn)它的時(shí)候產(chǎn)生動(dòng)作。Android有一些預(yù)置的view供開(kāi)發(fā)者使用——包括按鈕、文本域、滾動(dòng)條、菜單項(xiàng)、復(fù)選框等等。 </p><p> view層次結(jié)構(gòu)是由Activity.setContent
85、View() 方法放入activity的窗口之中的。content view是位于層次結(jié)構(gòu)根位置的View對(duì)象。(參見(jiàn)獨(dú)立的用戶(hù)界面文檔以獲取關(guān)于view及層次結(jié)構(gòu)的更多信息。) </p><p><b> 2 Service</b></p><p> service沒(méi)有可視化的用戶(hù)界面,而是在一段時(shí)間內(nèi)在后臺(tái)運(yùn)行。例如,一個(gè)service可以在用戶(hù)做其它事情的時(shí)
86、候在后臺(tái)播放背景音樂(lè)、從網(wǎng)絡(luò)上獲取數(shù)據(jù)或者計(jì)算一些東西并提供給需要這個(gè)運(yùn)算結(jié)果的activity使用。每個(gè)service都繼承自Service基類(lèi)。 </p><p> 一個(gè)媒體播放器播放播放列表中的曲目是一個(gè)不錯(cuò)的例子。播放器應(yīng)用程序可能有一個(gè)或多個(gè)activity來(lái)給用戶(hù)選擇歌曲并進(jìn)行播放。然而,音樂(lè)播放這個(gè)任務(wù)本身丌應(yīng)該由任何activity來(lái)處理,因?yàn)橛脩?hù)期望即使在他們離開(kāi)播放器應(yīng)用程序而開(kāi)始做別的事情
87、時(shí),音樂(lè)仍在繼續(xù)播放。為達(dá)到這個(gè)目的,媒體播放器activity可以啟動(dòng)一個(gè)運(yùn)行于后臺(tái)的service。系統(tǒng)將在這個(gè)activity不再顯示于屏幕乀后,仍維持音樂(lè)播放service的運(yùn)行。 </p><p> 連接至(綁定到)一個(gè)正在運(yùn)行的service(如果service沒(méi)有運(yùn)行,則啟動(dòng)之)是可能的。連接之后,你可以通過(guò)那個(gè)service暴露出來(lái)的接口不service進(jìn)行通訊。對(duì)于音樂(lè)service來(lái)說(shuō),這個(gè)
88、接口可以允許用戶(hù)暫停、回退、停止以及重新開(kāi)始播放。 </p><p> 如同activity和其它組件一樣,service運(yùn)行于應(yīng)用程序進(jìn)程的主線程內(nèi)。所以它不會(huì)對(duì)其它組件或用戶(hù)界面有任何妨礙,它們一般會(huì)派生一個(gè)新線程來(lái)執(zhí)行一些時(shí)間消耗型任務(wù)(比如音樂(lè)回放)。參見(jiàn)稍后的進(jìn)程和線程。 </p><p> 3 Broadcast receiver</p><p>
89、 broadcast receiver是一個(gè)與注于接收廣播通知信息,并做出相應(yīng)處理的組件。許多廣播是由系統(tǒng)代碼產(chǎn)生的——例如,通知時(shí)區(qū)改變、電池電量低、拍攝了一張照片或者用戶(hù)改變了語(yǔ)言選項(xiàng)。應(yīng)用程序也可以發(fā)起廣播——例如,通知其它應(yīng)用程序一些數(shù)據(jù)已經(jīng)下載到設(shè)備上并處于可用狀態(tài)。 </p><p> 一個(gè)應(yīng)用程序可以擁有任意數(shù)量的broadcast receiver,以對(duì)所有它認(rèn)為重要的通知信息予以響應(yīng)。所有的r
90、eceiver均繼承自BroadcastReceiver基類(lèi)。 </p><p> broadcast receiver沒(méi)有用戶(hù)界面。然而,它們可以啟動(dòng)一個(gè)activity來(lái)響應(yīng)它們收到的信息,或者也可以使用NotificationManager來(lái)通知用戶(hù)。通知可以用多種方式來(lái)吸引用戶(hù)的注意力──閃動(dòng)背光燈、震動(dòng)設(shè)備、播放聲音等等。通知一般是在狀態(tài)欄上放一個(gè)持麗的圖標(biāo),用戶(hù)可以打開(kāi)它并獲取消息。 </p&
91、gt;<p> 4 Content provider</p><p> content provider將一些特定的應(yīng)用程序數(shù)據(jù)供給其它應(yīng)用程序使用。數(shù)據(jù)可以存儲(chǔ)于文件系統(tǒng)、SQLite數(shù)據(jù)庫(kù)或其它有意丿的方式。content provider繼承于ContentProvider 基類(lèi),實(shí)現(xiàn)了一套使得其他應(yīng)用程序能夠檢索和存儲(chǔ)它所管理的類(lèi)型數(shù)據(jù)的標(biāo)準(zhǔn)方法。然而,應(yīng)用程序并不直接調(diào)用返些方法,而是
92、使用一個(gè) ContentResolver 對(duì)象,調(diào)用它的方法作為替代。ContentResolver可以與任何content provider進(jìn)行會(huì)話(huà);與其合作對(duì)任何相關(guān)的進(jìn)程間通訊進(jìn)行管理。 </p><p> 參閱獨(dú)立的Content Providers文檔以獲得更多關(guān)于使用content provider的信息。 </p><p> 每當(dāng)出現(xiàn)一個(gè)需要被特定組件處理的請(qǐng)求時(shí),And
93、roid會(huì)確保那個(gè)組件的應(yīng)用程序進(jìn)程處于運(yùn)行狀態(tài),必要時(shí)會(huì)啟動(dòng)它,并確保那個(gè)組件的一個(gè)合適的實(shí)例可用,必要時(shí)會(huì)創(chuàng)建那個(gè)實(shí)例。 </p><p> 1.1激活組件:intent</p><p> 當(dāng)接收到ContentResolver發(fā)出的請(qǐng)求后,content provider被激活。而其它三種組件——activity、service和broadcast receiver,被一種叫做i
94、ntent的異步消息所激活。intent是一個(gè)保存著消息內(nèi)容的Intent對(duì)象。對(duì)于activity和service來(lái)說(shuō),它指明了所請(qǐng)求的操作名稱(chēng),并指定了用來(lái)操作的數(shù)據(jù)的URI和其它一些信息。例如,它可以承載一個(gè)對(duì)一個(gè)activity的請(qǐng)求,讓它為用戶(hù)顯示一張圖片,或者讓用戶(hù)編輯一些文本。而對(duì)于broadcast receiver來(lái)說(shuō),Intent對(duì)象指明了所通報(bào)的操作。例如,它可以對(duì)所有感興趣的對(duì)象通報(bào)照相按鈕被按下。 </p
95、><p> 對(duì)于每種組件來(lái)說(shuō),激活的方法是不同的: </p><p> ? 1 通過(guò)傳遞一IntentContext.startActivity()Activity.startActivityForResult(以啟動(dòng)(或指定新工作給)一個(gè)activity。相應(yīng)的activity可以通過(guò)調(diào)用自身的 getIntent() 方法來(lái)查看最刜激活它的intent。Android通過(guò)調(diào)用ac
96、tivity的onNewIntent()方法來(lái)傳遞給它隨后的任何intent。</p><p> 一個(gè)activity經(jīng)常啟動(dòng)另一個(gè)activity。如果它期望它所啟動(dòng)的那個(gè)activity迒回一個(gè)結(jié)果,它會(huì)調(diào)用startActivityForResult()而不是startActivity()。例如,如果它啟動(dòng)了另外一個(gè)activity以使用戶(hù)挑選一張照片,它也許想知道哪張照片被選中了。其結(jié)果將會(huì)被封裝在一個(gè)
97、Intent對(duì)象中,并傳遞給發(fā)出調(diào)用的activity的onActivityResult() 方法。 </p><p> 2 通過(guò)傳遞一個(gè)Intent對(duì)象至Context.startService()以啟動(dòng)一個(gè)service(或向正在運(yùn)行的service給出一個(gè)新的指令)。Android調(diào)用此service的 onStart()方法并將Intent對(duì)象傳遞給它。 </p><p> 與
98、此類(lèi)似,一個(gè)intent可以被傳遞給 Context.bindService()以建立一個(gè)處于調(diào)用組件和目標(biāo)service乀間的活動(dòng)連接。此service會(huì)通過(guò)onBind() 方法的調(diào)用來(lái)獲取此Intent對(duì)象(如果此service尚未運(yùn)行,bindService()會(huì)先啟動(dòng)它)。例如,一個(gè)activity可以建立一個(gè)不前述的音樂(lè)回放service的連接,這樣它就可以提供給用戶(hù)一些途徑(用戶(hù)界面)來(lái)控制回放。這個(gè)activity可以調(diào)
99、用 bindService()來(lái)建立此連接,然后調(diào)用service中定之的方法來(lái)控制回放。 </p><p> 稍后的遠(yuǎn)程方法調(diào)用一節(jié)有關(guān)于如何綁定至一個(gè)service的更多細(xì)節(jié)。 </p><p> ? 3 應(yīng)用程序可以通過(guò)傳遞一個(gè)Intent對(duì)象至 Context.sendBroadcast() ,Context. sendOrderedBroadcast(), 以及Cont
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫(kù)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 外文翻譯---應(yīng)用程序基礎(chǔ)android developers
- android應(yīng)用程序基礎(chǔ)
- [雙語(yǔ)翻譯]安卓外文翻譯--android應(yīng)用程序的安全性
- 實(shí)現(xiàn)android手機(jī)音樂(lè)應(yīng)用-外文翻譯
- Android手機(jī)平臺(tái)應(yīng)用程序惡意行為動(dòng)態(tài)檢測(cè)研究.pdf
- [雙語(yǔ)翻譯]安卓外文翻譯--android應(yīng)用程序的安全性(英文)
- 2016年安卓外文翻譯--android應(yīng)用程序的安全性
- [雙語(yǔ)翻譯]安卓外文翻譯--android應(yīng)用程序的安全性中英全
- 一個(gè)權(quán)限的難題android智能手機(jī)上安裝應(yīng)用程序的權(quán)限外文翻譯
- android手機(jī)程序精簡(jiǎn)
- 一個(gè)權(quán)限的難題android智能手機(jī)上安裝應(yīng)用程序的權(quán)限外文翻譯
- 一個(gè)權(quán)限的難題:android智能手機(jī)上安裝應(yīng)用程序的權(quán)限外文翻譯
- 一個(gè)權(quán)限的難題android智能手機(jī)上安裝應(yīng)用程序的權(quán)限外文翻譯
- 2016年安卓外文翻譯--Android應(yīng)用程序的安全性.DOCX
- 面向Android手機(jī)應(yīng)用程序GUI的軟件測(cè)試研究與實(shí)踐.pdf
- 一個(gè)權(quán)限的難題android智能手機(jī)上安裝應(yīng)用程序的權(quán)限外文翻譯(英文)
- 一個(gè)權(quán)限的難題:Android智能手機(jī)上安裝應(yīng)用程序的權(quán)限外文翻譯.doc
- 2016年安卓外文翻譯--Android應(yīng)用程序的安全性(英文).PDF
- 一個(gè)權(quán)限的難題:Android智能手機(jī)上安裝應(yīng)用程序的權(quán)限外文翻譯.doc
- Android系統(tǒng)移植和應(yīng)用程序開(kāi)發(fā).pdf
評(píng)論
0/150
提交評(píng)論