Application components are the basic building blocks of an Android application. These components are organized by loosely coupled application manifest files.
AndroidManifest.xml
Describes each component of the application and how they interact.
Here are four main components that can be used in Android applications.
module | Description |
|---|---|
| Describe UI and handle the interaction between the user and the machine screen. |
| Handles background operations associated with the application. |
| Handles communication between the Android operating system and applications. |
| Deal with data and database management issues. |
3.7.1. Activities ¶
An activity identifies a single screen with a user interface. For example, a mail application can contain an activity to display a new mailing list, another activity to write a message, and another activity to read a message. When the application has more than one activity, one of them is marked to be displayed when the application starts.
One activity is
Activity
Class, as follows:
public class MainActivity extends Activity {
}
3.7.2. Services ¶
A service is a component that runs in the background and performs long-term operations. For example, a service can be a user playing music in the background while using different programs, or obtaining data through the network during an activity without blocking user interaction.
One service is
Service
Class, as follows:
public class MyService extends Service {
}
3.7.3. Broadcast Receivers ¶
The broadcast receiver simply responds to broadcast messages from other applications or systems. For example, an application can initiate a broadcast to let other applications know that some data has been downloaded to the device and is available to them. Therefore, the broadcast receiver will intercept these communications and take appropriate action.
The broadcast receiver is
BroadcastReceiver
Class, with each message beginning with a
Intent
Object to broadcast.
public class MyReceiver extends BroadcastReceiver {
}
3.7.4. Content Providers ¶
The content provider component provides data from one application to another by request. These requests are made by
ContentResolver
Class to handle the. This data can be stored in a file system, database, or other place.
The content provider is
ContentProvider
Class and implements a standard set of API for other applications to perform transactions.
public class MyContentProvider extends ContentProvider {
}
We will cover the application components through the details of these tags in separate chapters.
3.7.5. Accessory component ¶
There are some attachment components for the entities mentioned above, the logic between them, and the construction of connections between them. These components are as follows:
module | Description |
|---|---|
| Represents an action or part of a user interface in an activity. |
| UI elements drawn on the screen, including buttons, lists, etc. |
| Inheritance of View that controls the screen format and shows the appearance of the view. |
| Message connections between components. |
| External elements, such as string resources, constant resources, and picture resources. |
| The configuration file for the application. |