2023年全國(guó)碩士研究生考試考研英語(yǔ)一試題真題(含答案詳解+作文范文)_第1頁(yè)
已閱讀1頁(yè),還剩14頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、<p>  Application Fundamentals</p><p>  Android applications are written in the Java programming language. The compiled Java code — along with any data and resource files required by the application — i

2、s 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; it's the file users downloa

3、d 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 world:</p><p>  1. By default, every

4、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 no longer needed and system resources are requir

5、ed 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 applications.</p><p>  3. By default, each a

6、pplication 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 — although there are ways to export them to other ap

7、plications 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's files. To conserve system resources, applicat

8、ions 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 feature of Android is that one application can ma

9、ke 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

10、 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 application or link to it. Rather, it simply star

11、ts 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 that part. Therefore, unlike applications on most

12、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 components that the system can instantiate and run

13、as needed. There are four types of components:</p><p>  Activities</p><p>  An activity presents a visual user interface for one focused endeavor the user can undertake. For example, an activity

14、 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 that shows a list of contacts to send messages to,

15、 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><p>  An application might consist of jus

16、t 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 design. Typically, one of the

17、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 start the next one.</p>

18、;<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 can also make use of additi

19、onal 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 on-screen.</p><

20、;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. Parent views contain and organ

21、ize 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 activity's interac

22、tion 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 views that you can use — incl

23、uding 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() method. The content view is th

24、e 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><p>  A service do

25、esn'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

26、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 playing songs from a play li

27、st. 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

28、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 &l

29、t;/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 through an interface that t

30、he 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, services run in the main threa

31、d 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 and Threads, later.</p&g

32、t;<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 system code — for example, ann

33、ouncements 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 example, to let other appl

34、ications 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 announcements it consider

35、s 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 the information they recei

36、ve, 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 so on. They typically pla

37、ce 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 application's data availab

38、le 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 to implement a standard set

39、 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 and call its </p>&

40、lt;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 component, Android makes

41、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><p>  Activatin

42、g 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 broadcast receivers — are

43、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 specifies the URI of the data t

44、o 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 announced. For example, it might announce to interes

45、ted parties that the camera button has been pressed.</p><p>  There are separate methods for activating each type of component:</p><p>  1. An activity is launched (or given something new to do)

46、 by passing an Intent object to</p><p>  Context.startActivity() or Activity.startActivityForResult(). The responding activity can look at the initial intent that caused it to be launched by calling its getI

47、ntent() 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 back from the activity it's starting, it calls

48、 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 (or new instructions are given to an ongoing servic

49、e) 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 passed to Context.bindService() to establish an ongo

50、ing 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, bindService() can optionally start it.) Fo</p>

51、<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 passing an Intent object to methods like Context.sendB

52、roadcast(), Context.sendOrderedBroadcast(), and Context.sendStickyBroadcast() in any of their variations.</p><p>  Android delivers the intent to all interested broadcast receivers by calling their onReceive

53、() methods. For more on intent messages, see the separate article, Intents and Intent Filters.</p><p>  Shutting down components</p><p>  A content provider is active only while it's respond

54、ing 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 shut down these components.</p><p>  Ac

55、tivities, 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 conversation continues. Similarly, services may also

56、 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 calling its finish() method. One activity can shut

57、down another activity (one it started with startActivityForResult()) by calling finishActivity().</p><p>  2. A service can be stopped by calling its stopSelf() method, or by calling Context.stopService().&l

58、t;/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 th

59、is 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, ap

60、plications 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

61、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, such as naming any libraries the application needs t

62、o 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

63、 application's components. For example, an activity might be declared as follows:</p><p>  The name attribute of the <activity> element names the Activity subclass that implements the activity. The

64、 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 components are declared in a similar way — <ser

65、vice> elements for services, <receiver> elements for broadcast receivers, and <provider> elements for content providers. Activities, services, and content providers that are not declared in the manifest ar

66、e 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 (as BroadcastReceiver objects) and registered wi

67、th 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>  Intent filters</p><p>  An Intent object c

68、an 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 explicitly named, Android must locate the best com

69、ponent 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 the kinds of intents the component is able to hand

70、le. Like other essential information about the</p><p>  The first filter in the example — the combination of the action "android.intent.action.MAIN" and the category</p><p>  "and

71、roid.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 users can launch on the device. In other words,

72、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 filter declares an action that the activity can perf

73、orm 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't have any filters, it can be activated only

74、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 instantiated directly as an IntentFilter object.

75、 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>  應(yīng)用程序基礎(chǔ)Android Developers</p><p>  A

76、ndroid應(yīng)用程序使用Java編程語(yǔ)言開(kāi)發(fā)。aapt工具把編譯后的Java代碼連同應(yīng)用程序所需的其他數(shù)據(jù)和資源文件一起打包到一個(gè)Android包文件中,這個(gè)文件使用.apk作為擴(kuò)展名。此文件是分發(fā)并安裝應(yīng)用程序到移動(dòng)設(shè)備的載體;是用戶下載到他們的設(shè)備的文件。單一.apk文件中的所有代碼被認(rèn)為是一個(gè)應(yīng)用程序。</p><p>  從多個(gè)角度來(lái)看,每個(gè)Android應(yīng)用程序都存在于它自己的世界之中:</p&g

77、t;<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)用程序代碼是隔離運(yùn)行的。 </p><p>  3 默認(rèn)情況下,每個(gè)應(yīng)用程

78、序均被賦予一個(gè)唯一的Linux用戶ID,并加以權(quán)限設(shè)置,使得應(yīng)用程序的文件僅對(duì)此用戶及此應(yīng)用程序可見(jiàn)——盡管也有其它的方法使得這些文件同樣能為其他應(yīng)用程序所訪問(wèn)。 </p><p><b>  1 應(yīng)用程序組件</b></p><p>  Android的一個(gè)核心特性就是一個(gè)應(yīng)用程序可以使用其它應(yīng)用程序的元素(如果那個(gè)應(yīng)用程序允許的話)。例如,如果你的應(yīng)用程序需要顯示

79、一個(gè)圖片卷動(dòng)列表,而另一個(gè)應(yīng)用程序已經(jīng)開(kāi)發(fā)了一個(gè)合用的而又允許別的應(yīng)用程序使用的話,你可以直接調(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)用程序的任何一部分被需要時(shí)啟動(dòng)一個(gè)此應(yīng)用程序的進(jìn)程,并將那個(gè)部分的Java對(duì)象實(shí)例化。因此,不像其它大多數(shù)系統(tǒng)

80、上的應(yīng)用程序,Android應(yīng)用程序并沒(méi)有為應(yīng)用程序提供一個(gè)單獨(dú)的入口點(diǎn)(比如說(shuō),沒(méi)有main()函數(shù)),而是為系統(tǒng)提供了可以實(shí)例化和運(yùn)行所需的必備組件。一共有四種組件類型: </p><p>  1 Activity </p><p>  activity是為用戶操作而展示的可視化用戶界面。例如,一個(gè)activity可以展示一個(gè)菜單項(xiàng)列表供用戶選擇,戒者顯示一些包含說(shuō)明文字的照片。一個(gè)短

81、消息應(yīng)用程序可以包括一個(gè)用于顯示要發(fā)送消息到的聯(lián)系人列表的activity,一個(gè)給選定的聯(lián)系人寫(xiě)短信的activity以及翻閱以前的短信或改變?cè)O(shè)置的其他activity。盡管它們一起組成了一個(gè)內(nèi)聚的用戶界面,但其中每個(gè)activity都不其它的保持獨(dú)立。每一個(gè)都實(shí)現(xiàn)為以Activity類為基類的子類。 </p><p>  一個(gè)應(yīng)用程序可以只有一個(gè)activity,戒者,如剛才提到的短信應(yīng)用程序那樣,包含很多個(gè)。

82、每個(gè)activity的作用,以及有多少個(gè)activity,當(dāng)然是取決于應(yīng)用程序及其設(shè)計(jì)的。一般情況下,總有一個(gè)應(yīng)用程序被標(biāo)記為用戶在應(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)行繪制。一般情況下,這個(gè)窗口是滿屏的,但它也可以是一個(gè)小的位于其它窗口之上的浮動(dòng)窗口。一個(gè)activity也

83、可以使用附加窗口——例如,一個(gè)在activity運(yùn)行過(guò)程中彈出的供用戶響應(yīng)的對(duì)話框,戒是一個(gè)當(dāng)用戶選擇了屏幕上特定項(xiàng)目后顯示的必要信息的窗口。 </p><p>  窗口顯示的可視內(nèi)容是由一系列層次化view構(gòu)成的,這些view均繼承自 View 基類。每個(gè)view均控制著窗口中一塊特定的矩形區(qū)域。父級(jí)view包含并組織其子view的布局。葉節(jié)點(diǎn)view(位于層次結(jié)構(gòu)最底端)在它們控制的矩形區(qū)域中進(jìn)行繪制,并對(duì)用

84、戶直達(dá)其區(qū)域的操作做出響應(yīng)。因此,view是activity與用戶進(jìn)行交互的界面。例如,view可以顯示一個(gè)小圖片,并在用戶指點(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.setContentView() 方法放入activity的窗口之中的。content view是位于層次結(jié)構(gòu)根

85、位置的View對(duì)象。(參見(jiàn)獨(dú)立的用戶界面文檔以獲取關(guān)于view及層次結(jié)構(gòu)的更多信息。) </p><p>  2 Service </p><p>  service沒(méi)有可視化的用戶界面,而是在一段時(shí)間內(nèi)在后臺(tái)運(yùn)行。例如,一個(gè)service可以在用戶做其它事情的時(shí)候在后臺(tái)播放背景音樂(lè)、從網(wǎng)絡(luò)上獲取數(shù)據(jù)或者計(jì)算一些東西并提供給需要這個(gè)運(yùn)算結(jié)果的activity使用。每個(gè)service都繼承自

86、Service基類。 </p><p>  一個(gè)媒體播放器播放播放列表中的曲目是一個(gè)不錯(cuò)的例子。播放器應(yīng)用程序可能有一個(gè)或多個(gè)activity來(lái)給用戶選擇歌曲并進(jìn)行播放。然而,音樂(lè)播放這個(gè)任務(wù)本身丌應(yīng)該由任何activity來(lái)處理,因?yàn)橛脩羝谕词乖谒麄冸x開(kāi)播放器應(yīng)用程序而開(kāi)始做別的事情時(shí),音樂(lè)仍在繼續(xù)播放。為達(dá)到這個(gè)目的,媒體播放器activity可以啟動(dòng)一個(gè)運(yùn)行于后臺(tái)的service。系統(tǒng)將在這個(gè)activi

87、ty不再顯示于屏幕乀后,仍維持音樂(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è)接口可以允許用戶暫停、回退、停止以及重新開(kāi)始播放。 </p><p>  如同activity和其它組件

88、一樣,service運(yùn)行于應(yīng)用程序進(jìn)程的主線程內(nèi)。所以它不會(huì)對(duì)其它組件或用戶界面有任何妨礙,它們一般會(huì)派生一個(gè)新線程來(lái)執(zhí)行一些時(shí)間消耗型任務(wù)(比如音樂(lè)回放)。參見(jiàn)稍后的進(jìn)程和線程。 </p><p>  3 Broadcast receiver </p><p>  broadcast receiver是一個(gè)與注于接收廣播通知信息,并做出相應(yīng)處理的組件。許多廣播是由系統(tǒng)代碼產(chǎn)生的——例如,

89、通知時(shí)區(qū)改變、電池電量低、拍攝了一張照片或者用戶改變了語(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)。所有的receiver均繼承自BroadcastReceiver基類。 </p><p>  broadcas

90、t receiver沒(méi)有用戶界面。然而,它們可以啟動(dòng)一個(gè)activity來(lái)響應(yīng)它們收到的信息,或者也可以使用NotificationManager來(lái)通知用戶。通知可以用多種方式來(lái)吸引用戶的注意力──閃動(dòng)背光燈、震動(dòng)設(shè)備、播放聲音等等。通知一般是在狀態(tài)欄上放一個(gè)持麗的圖標(biāo),用戶可以打開(kāi)它并獲取消息。 </p><p>  4 Content provider </p><p>  conte

91、nt provider將一些特定的應(yīng)用程序數(shù)據(jù)供給其它應(yīng)用程序使用。數(shù)據(jù)可以存儲(chǔ)于文件系統(tǒng)、SQLite數(shù)據(jù)庫(kù)或其它有意丿的方式。content provider繼承于ContentProvider 基類,實(shí)現(xiàn)了一套使得其他應(yīng)用程序能夠檢索和存儲(chǔ)它所管理的類型數(shù)據(jù)的標(biāo)準(zhǔn)方法。然而,應(yīng)用程序并不直接調(diào)用返些方法,而是使用一個(gè) ContentResolver 對(duì)象,調(diào)用它的方法作為替代。ContentResolver可以與任何content

92、 provider進(jìn)行會(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í),Android會(huì)確保那個(gè)組件的應(yīng)用程序進(jìn)程處于運(yùn)行狀態(tài),必要時(shí)會(huì)啟動(dòng)它,并確保那個(gè)組件的一個(gè)合適的實(shí)例可用,必要時(shí)會(huì)創(chuàng)建那個(gè)實(shí)例。

93、 </p><p>  1.1激活組件:intent</p><p>  當(dāng)接收到ContentResolver發(fā)出的請(qǐng)求后,content provider被激活。而其它三種組件——activity、service和broadcast receiver,被一種叫做intent的異步消息所激活。intent是一個(gè)保存著消息內(nèi)容的Intent對(duì)象。對(duì)于activity和service來(lái)說(shuō),它

94、指明了所請(qǐng)求的操作名稱,并指定了用來(lái)操作的數(shù)據(jù)的URI和其它一些信息。例如,它可以承載一個(gè)對(duì)一個(gè)activity的請(qǐng)求,讓它為用戶顯示一張圖片,或者讓用戶編輯一些文本。而對(duì)于broadcast receiver來(lái)說(shuō),Intent對(duì)象指明了所通報(bào)的操作。例如,它可以對(duì)所有感興趣的對(duì)象通報(bào)照相按鈕被按下。 </p><p>  對(duì)于每種組件來(lái)說(shuō),激活的方法是不同的: </p><p>  ?

95、 1 通過(guò)傳遞一IntentContext.startActivity()Activity.startActivityForResult(以啟動(dòng)(或指定新工作給)一個(gè)activity。相應(yīng)的activity可以通過(guò)調(diào)用自身的 getIntent() 方法來(lái)查看最刜激活它的intent。Android通過(guò)調(diào)用activity的onNewIntent()方法來(lái)傳遞給它隨后的任何intent。</p><p>  

96、一個(gè)activity經(jīng)常啟動(dòng)另一個(gè)activity。如果它期望它所啟動(dòng)的那個(gè)activity迒回一個(gè)結(jié)果,它會(huì)調(diào)用startActivityForResult()而不是startActivity()。例如,如果它啟動(dòng)了另外一個(gè)activity以使用戶挑選一張照片,它也許想知道哪張照片被選中了。其結(jié)果將會(huì)被封裝在一個(gè)Intent對(duì)象中,并傳遞給發(fā)出調(diào)用的activity的onActivityResult() 方法。 </p>

97、<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>  與此類似,一個(gè)intent可以被傳遞給 Context.bindService()以建立一個(gè)處于調(diào)用組件和目標(biāo)service乀

98、間的活動(dòng)連接。此service會(huì)通過(guò)onBind() 方法的調(diào)用來(lái)獲取此Intent對(duì)象(如果此service尚未運(yùn)行,bindService()會(huì)先啟動(dòng)它)。例如,一個(gè)activity可以建立一個(gè)不前述的音樂(lè)回放service的連接,這樣它就可以提供給用戶一些途徑(用戶界面)來(lái)控制回放。這個(gè)activity可以調(diào)用 bindService()來(lái)建立此連接,然后調(diào)用service中定之的方法來(lái)控制回放。 </p><

99、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(), 以及Context.sendStickyBroadcast()和其它類似方法來(lái)發(fā)起一個(gè)廣播。Android會(huì)調(diào)用所有對(duì)此廣播有興趣的br

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 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ì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論