Easy Tutorial
❮ Android Resources Android Overview ❯

Android Application Components

Application components are the foundational building blocks of an Android application. These components are loosely coupled and organized by the application manifest file. The AndroidManifest.xml describes each component of the application and how they interact.

The following are the four main components that can be used in an Android application.

Component Description
Activities Describe the UI and handle user interaction with the device screen.
Services Handle background operations associated with the application.
Broadcast Receivers Handle communication between the Android OS and applications.
Content Providers Handle data and database management issues.

Activities

An activity represents a single screen with a user interface. For example, an email application might include one activity for displaying new email lists, another for composing emails, and another for reading emails. When an application has more than one activity, one of them is marked to be displayed when the application is launched.

An activity is a subclass of the Activity class, as shown below:

public class MainActivity extends Activity {

}

Services

A service is a component that runs in the background to perform long-running operations. 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 in an activity.

A service is a subclass of the Service class, as shown below:

public class MyService extends Service {

}

Broadcast Receivers

A broadcast receiver simply responds to broadcast messages from other applications or from the system. 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 for them to use. Thus, a broadcast receiver will intercept these communications and take appropriate action.

A broadcast receiver is a subclass of the BroadcastReceiver class, and each message is broadcast as an Intent object.

public class MyReceiver extends BroadcastReceiver {

}

Content Providers

A content provider component supplies data from one application to another upon request. These requests are handled by methods of the ContentResolver class. The data can be stored in the file system, the database, or somewhere else entirely.

A content provider is a subclass of the ContentProvider class and implements a standard set of APIs to allow other applications to perform transactions.

public class MyContentProvider extends ContentProvider {

}

We will cover these components in detail in separate sections.

Additional Components

There are some additional components for the entities mentioned above, their logic, and their connections. These components include:

Component Description
Fragments Represent a behavior or a portion of the user interface within an activity.
Views UI elements drawn on the screen, including buttons, lists, etc.
Layouts Inherit from View to control screen formatting and display of views.
Intents Messaging wiring between components.
Resources External elements, such as string resources, constant resources, and image resources.
Manifest The configuration file for the application.
❮ Android Resources Android Overview ❯