However, there are ways for an application to share data with other applications and for an application to access system services:
four types of application components
An activity is implemented as a subclass of Activity
and you can learn more about it in the Activities developer guide.
A 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.
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.
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.