Android Learning-Application Fundamentals

Application Fundamentals 

URL: http://developer.android.com/guide/topics/fundamentals.html

However, there are ways for an application to share data with other applications and for an application to access system services:

  • It's possible to arrange for two applications to share the same Linux user ID, in which case they are able to access each other's files. To conserve system resources, applications with the same user ID can also arrange to run in the same Linux process and share the same VM (the applications must also be signed with the same certificate).
  • An application can request permission to access device data such as the user's contacts, SMS messages, the mountable storage (SD card), camera, Bluetooth, and more. All application permissions must be granted by the user at install time.

four types of application components

Activities
An   activity   represents a single screen with a user interface. For example, an email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. Alt hough the activities work together to form a cohesive user experience in the email application, each one is independent of the others. As such, a different application can start any one of these activities (if the email application allows it). For example, a camera application can start the activity in the email application that composes new mail, in order for the user to share a picture.

An activity is implemented as a subclass of Activity and you can learn more about it in the Activities developer guide.

Services

service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity. Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it.

A service is implemented as a subclass of Service and you can learn more about it in the Services developer guide.

Content providers
content provider manages a shared set of application data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access. Through the content provider, other application s can query or even modify the data (if the content provider allows it). For example, the Android system provides a content provider that manages the user's contact information. As such, any application with the proper permissions can query part of the content provider (such as  ContactsContract.Data) to read and write information about a particular person.

Content providers are also useful for reading and writing data that is private to your application and not shared. For example, the Note Pad sample application uses a content provider to save notes.

A content provider is implemented as a subclass of ContentProvider and must implement a standard set of APIs that enable other applications to perform transactions. For more information, see the Content Providers developer guide.

Broadcast receivers
broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. Applications can also initiate broadcasts—for example, to let other applications know that some data has been downloaded to the device and is available for them to use. Although broadcast receivers don't display a user interface, they may  create a status bar notification to alert the user when a broadcast event occurs. More commonly, though, a broadcas t receiver is just a "gateway" to other components and is intended to do a very minimal amount of work. For instance, it might initiate a service to perform some work based on the event.

A broadcast receiver is implemented as a subclass of BroadcastReceiver and each broadcast is delivered as anIntent object. For more information, see the BroadcastReceiver class.

A unique aspect of the Android system design is that any application can start another application’s component

When the system starts a component, it starts the process for that application (if it's not already running) and instantiates the classes needed for the component. 

Therefore, unlike applications on most other systems, Android applications don't have a single entry point (there's nomain() function, for example).

 to activate a component in another application, you must deliver a message to the system that specifies yourintent to start a particular component. The system then activates the component for you.

activities(startActivity or startActivityForResult), services(startService, bindService), and broadcast receivers—are activated by an asynchronous message called an intent

initiate a broadcast: sendBroadcast, sendOrderedBroadcast or sendStickyBroadcast

perform a query to a content provider by calling query on a contentResolver

The other component type, content provider, is not activated by intents. Rather, it is activated when targeted by a request from a ContentResolver.

Activities, services, and content providers that you include in your source but do not declare in the manifest are not visible to the system and, consequently, can never run. However, broadcast receivers can be either declared in the manifest or created dynamically in code (as BroadcastReceiver objects) and registered with the system by callingregisterReceiver().

The way the system identifies the components that can respond to an intent is by comparing the intent received to the intent filters provided in the manifest file of other applications on the device.

Most of the requirement declarations are informational only and the system doesn't read them, but external services such as Android market do read them in order to provide filtering for users when they search for applications from their device.

你可能感兴趣的:(android)