外文翻译---应用程序基础androiddevelopers-android(编辑修改稿)内容摘要:
s 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, the Intent 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 ponent: 1. An activity is launched (or given something new to do) by passing an Intent object to () or (). The responding activity can look at the initial intent that caused it to be launched by calling its getIntent() method. Android calls the activity39。 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 it39。 s starting, it calls startActivityForResult() instead of startActivity(). For example, if it starts an activity that lets the user pick a photo, it might expect to be returned the 长春理工大学光电信息学院毕业设计 5 chosen photo. The result is returned in an Intent object that39。 s passed to the calling activity39。 s onActivityResult() method. 2. A service is started (or new instructions are given to an ongoing service) by passing an Intent object to (). Android calls the service39。 s onStart() method and passes it the Intent object. Similarly, an intent can be passed to () to establish an ongoing connection between the calling ponent 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.) For example, an activity might establish a connection with the music playback service mentioned earlier so that it can provide the user with the means (a user interface) for controlling the playback. The activity would call bindService() to set up that connection, and then call methods defined by the service to affect the playback. A later section, Remote procedure calls, has more details about binding to a service. 3. An application can initiate a broadcast by passing an Intent object to methods like (), (), and () in any of their variations. Android delivers 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. Shutting down ponents A content provider is active only while it39。 s responding to a request from a ContentResolver. And a broadcast receiver is active only while it39。 s responding to a broadcast message. So there39。 s no need to explicitly shut down these ponents. Activities, on the other hand, provide the user interface. They39。 re in a longrunning conversation with the user and may remain active, even 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: 1. An activity can be shut down by calling its finish() method. One activity can shut down another activity (one it started with startActivityForResult()) by calling finishActivity(). 2. A service can be stopped by calling its stopSelf() method, or by calling (). 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 ponents. A later section, Component Lifecycles, discusses this possibility and its ramifications in more 长春理工大学光电信息学院毕业设计 6 detail. The manifest file Before Android can start an application ponent, it must learn that the ponent exists. Therefore, applications declare their ponents in a manifest file that39。 s bundled into the Android package, the .apk file that also holds the application39。 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。 s ponents, such 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. But the principal task of the manifest is to inform Android about the application39。 s ponents. For example, an activity might be declared as follows: The name attribute of the activity element names the 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. The other ponents are declared in a similar way — service elements for services, r。外文翻译---应用程序基础androiddevelopers-android(编辑修改稿)
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。
用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。