【正文】
pplication developer defnes one activity per “screen.” Activities start each other, possibly passing and returning values. Only one activity 浙江大學城市學院畢業(yè)論文 外文翻譯 on the system has keyboard and ocessing focus at a time。 all others are ponents perform background processing. When an activity needs to perform some operation that must continue after the user interface disappears (such as download a fle or play music), it monly starts a service specifcally designed for that action. The developer can also use services as applicationspecifc daemons, possibly starting on boot. Services often define an interface for Remote Procedure Call (RPC) that other system ponents can use to send mands and retrieve data, as well as register callbacks. Content provider ? ponents store and share data using a relational database interface. Each content provider has an associated “authority” describing the content it contains. Other ponents use the authority name as a handle to perform SQL queries (such as SELECT, INSERT, or DELETE) to read and write content. Although content providers typically store values in database records, data retrieval is implementationspecifc—for example, fles are also shared through content provider receiver? ponents act as mailboxes for messages from other applications. Commonly, application code broadcasts messages to an implicit destination. Broadcast receivers thus subscribe to such destinations to receive the messages sent to it. Application code can also address a broadcast receiver explicitly by including the namespace assigned to its containing application. Figure 1 shows the FriendTracker and FriendViewer applications containing the diferent ponent types. The developer specifes ponents using a manifest fle (also used to defne policy as described later). There are no restrictions on the number of ponents an application defnes for each type, but as a convention, one pone nt has the same name as the application. Frequently, this is an activity, as in the FriendViewer application. This activity usually indicates the primary activity that the system application launcher uses to start the user interface。 however, the specifc activity chosen on launch is marked by meta information in the manifest. In the FriendTracker application, for example, the FriendTrackerControl activity is marked as the main user interface entry point. In this case, we reserved the name “FriendTracker” for the service ponent performing the core application FriendTracker application contains each of the four ponent types. The FriendTracker service polls an external service to discover friends’ locations. In our example code, we generate locaFriendTracker application BootReceiver Broadcast receiver ActivityFriendTracker FriendProvider Content provider Service FriendTracker control FriendViewer application FriendReceiver Broadcast receiver Activity FriendTracker Activity FriendViewer Figure 1. Example Android application. The 浙江大學城市學院畢業(yè)論文 外文翻譯 FriendTracker and FriendViewer applications consist of multiple ponents of different types, each of which provides a different set of functionalities. Activities provide a user interface, services execute background processing, content providers are data storage facilities, and broadcast receivers act as mailboxes for messages from other randomly, but extending the ponent to interface with a Web service is straightforward. The FriendProvider content provider maintains the most recent geographic coordinates for friends, the FriendTrackerControl activity defnes a user interface for starting and stopping the tracking functionality, and the BootReceiver broadcast receiver obtains a notifcation from the system once it boots (the application uses this to utomatically start the FriendTracker service).The FriendViewer application bis primarily concerned with showing information about friends’ locations. The FriendViewer activity lists all friends and their geographic coordinates, and the FriendMap activity displays them on a map. The FriendReceiver broadcast receiver waits for messages that indicate the physical phone is near a particular friend and displays a message to the user upon such an event. Although we could have placed these ponents within the FriendTracker application, we created a separate application to demonstrate crossapplication munication. dditionally, by separating the tracking and user interface logic, we can create alternative user interfaces with different displays and features—that is, many applications can reuse the logic performed in Interaction The primary mechanism for ponent interaction is an intent, which is simply a message object containing a destination ponent address and data. The Android API defnes methods that accept intents, and uses that information to start activities (startActivity(Intent)), start services (startService (Intent)), and broadcast messages (sendBroadcast(Intent)). The invocation of these methods tells the Android framework to begin executing code in the target application. This process of interponent munication is known as an action. Simply put, an intent object defnes the “intent” to perform an “action.”O(jiān)ne of Android’s most powerful features is the fexibility allowed by its intentaddressing mechanism. Although developers can uniquely address a target ponent using its application’s namespace, they can also specify an implicit name. In the latter case, the system determines the best ponent for an action by considering the set of installed applications and user choices. The implicit name is called an action string because it specifes the type of requested action—for example, if the “VIEW” action string is specifed in an intent with data felds pointing to an image fle, the system will 浙江大學城