Android Application Components
Android Application Components
An application component is a basic building block of an Android application. These components are loosely coupled organizations by the application manifest file. AndroidManifest.xml describes each component of the application and how they interact.
The four main components that can be used in an Android application are as follows.
| Component | Description |
|---|---|
| Activities | Describe the UI and handle the interaction between the user and the machine screen. |
| Services | Handling background operations associated with applications. |
| Broadcast Receivers | Handling communication between the Android operating system and applications. |
| Content Providers | Handling data and database management issues. |
Activities
An activity identifies a single screen with a user interface. For example, an email application can have one activity to display a list of new emails, another activity to compose an email, and another activity to read an email. When an application has more than one activity, one of them will be marked to display when the application starts.
An activity isa subclass of the Activity class, as shown below:Services
public class MainActivity extends Activity {
}
A service is a component that runs in the background and performs long-running operations. For example, a service could be playing music in the background while the user is using different applications, or fetching data over the network in an activity without blocking user interaction.
A service is
a subclass of the Service class, as shown below:ServiceSubclasses of the class, as shown below:
public class MyService extends Service {
}
Broadcast Receivers
A BroadcastReceiver simply responds to broadcast messages sent from other applications or systems. For example, an application can send a broadcast to let other applications know that some data has been downloaded to the device and is available for them to use. Therefore, the BroadcastReceiver intercepts these communications and takes appropriate action.
A BroadcastReceiver isa subclass of the BroadcastReceiverclass, and each message is broadcast in the form of anIntentobject.
public class MyReceiver extends BroadcastReceiver {
}
Content Providers
Content providers provide data from one application to another application through requests. These requests are handled by the methods of theContentResolverclass. This data can be stored in the file system, database, or other places.
A content provider is asubclass of the ContentProviderclass, implementing a set of standard APIs so that other applications can perform transactions.
public class MyContentProvider extends ContentProvider {
}
We will cover the details of these application components in separate chapters using these tags.
Attachment component
Some components are used for the entities mentioned above, their logic, and the construction of the connections between them. These components are as follows:
| Components | Description |
|---|---|
| Fragments | Represents a behavior or a part of the user interface in an activity. |
| Views | UI elements drawn on the screen, including buttons, lists, etc. |
| Layouts | Controls the screen format, the inheritance of the View that displays the view appearance. |
| Intents | Message connections between components. |
| Resources | External elements, such as string resources, constant resources, and image resources. |
| Manifest | The configuration file of the application. |