Android apps have a distinctive structure compared to other platforms such as iOS, Windows, or macOS. Whether you’re just starting in Android app development or want to deepen your knowledge, it’s important to understand the key components that makeup Android apps.
In this article, Bardimin will discuss Activity, Fragment, Intent, Broadcast Receiver, and Service in detail, which are the core components of ensuring Android apps work properly.
By understanding how each of these components works and interacts, you can create an application that is not only efficient but also easy to manage and develop further. Whether you’re a beginner or an experienced developer, this guide will help you understand the structure of Android apps and implement them in your projects.
Let’s start by exploring Activity, the basic components responsible for displaying the user interface (UI) within Android apps.

1. Activity: Basic User Interface
Activity is one of the most important elements in Android app development. This element is in charge of displaying the (UI) user interface and regulating user interaction with the application. Each Activity typically represents a single view within the app, and Android apps often consist of multiple Activity that collaborate with each other to provide an all-around user experience.
For example, in a calendar app:
- Activity First: Displays a list of users’ daily schedules.
- Activity Second: Allows users to add new appointments by filling out forms.
Setiap Activity is designed to perform specific tasks and can be accessed separately, both from within the app itself and from other apps. This makes Activity a highly flexible and reusable component.
Main Characteristics of Activity
- Independent: Each Activity operates independently and is independent of other Activity.
- Can be Called by Intent: Activity can be accessed using Intent, either explicitly (directly mentioning the class name) or implicitly (specifying the action you want to take).
- (Lifecycle) Lifecycle: Activity has lifecycles managed by Android systems, such as onCreate(), onStart(), onResume(), and onDestroy(), which allow developers to control the behavior of the app when Activity is created, displayed, or stopped.
How Activity Works
Activity operates autonomously, which means that each Activity can function without relying on other Activity. This allows Activity to be reused in a variety of applications.
Activity Reuse Examples
- Email Apps: An email app may have an Activity to send messages. Activity can be used by other apps, such as the calendar app, to send meeting invitations without the need to create a new Activity from scratch.
- Social Media Apps: Activity for sharing content can be reused in various apps, such as photo galleries or news apps.
The ability to reuse this Activity not only saves time in development but also maintains the consistency of the user interface across various applications.
Communication Between Activities
Activity can’t interact in person. Alternatively, Android provides a mechanism called Intent to start another Activity and transfer data between Activity.
How Intent Works
You can use Intent to open a new Activity from an active Activity. For example, when a user presses the “Add Appointment” button in the calendar app, Intent will open a new Activity to fill out the appointment form.
Intent can also carry information from one Activity to another Activity. For example, you can send appointment details from the Activity appointment list to the Activity appointment details.
Examples of Intent Usage
- E-commerce Apps: When users select products from the list, Intent is used to open product details Activity and send information such as product names, prices, and images.
- Chat app: Intent used to open chat Activity and send data such as user IDs and contact names.
2. Fragment: Modularity in the User Interface
Fragment is an important element in Android app development that allows breaking Activity into small, modular parts. Each Fragment has its own (UI) user interface and logic, making it easier to manage a more flexible and dynamic interface.
By leveraging Fragment, you can create apps that are more responsive to different screen sizes and device orientations, such as phones, tablets, or foldable devices.
Benefits of Using Fragment
Fragment provides some key benefits in Android app development:
- Modularity: By dividing Activity into Fragment, you can manage each part of the interface separately, which makes it easier to develop and maintain code.
- Flexibility: Fragment allows the appearance of several parts of the interface in a single Activity, especially useful for devices with large screens such as tablets.
- Reusability: Fragment can be reused across a variety of Activity, reducing code repetition and improving development efficiency.
- Adaptability: Fragment easy interface customization for different screen sizes and device orientations.
Examples of Using Fragments in E-commerce Applications:
- Fragment First: Displays the list of products on the left side of the screen.
- Fragment Second: Displays product details on the right side of the screen.
- On mobile, only one Fragment is displayed at a time, while on tablets, both Fragment can be displayed at the same time.
How Fragment Works
Fragment have a lifecycle similar to Activity, including methods such as onCreateView(), onStart(), and onDestroyView(). However, the life cycle is Fragment related to the Activity that displays it.
You can add Fragment to Activity by using FragmentManager and FragmentTransaction.
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.fragment_container, new MyFragment());
fragmentTransaction.commit();Fragment cannot communicate with each other directly. Alternatively, communication is carried out through the Activity that houses the Fragment or by using an interface (interface) to transfer data.
3. Intent: Communication Mechanism Between Components
Intent is one of the key mechanisms in Android app development. This component is used to start an Activity, Service, or send Broadcast. In addition, Intent also allows communication between components within the same application or even between different applications.
Intent can be differentiated into:
- Explicit: Calls a specific component (such as Activity or Service) by mentioning its class name directly.
- Implicit: Specify the action you want to take or the type of data you want to process, and the Android system will select the most appropriate component.
Types of Intent
1. Explicit Intent
Explicit Intent is used when you know clearly which component you want to call, such as a specific Activity or Service in your application.
How It Works:
You specify the name of the component class you want to access. For example, starting a new Activity to display product details.
Intent intent new Intent(this, ProductDetailActivity.class);
startActivity(intent);Usage Example:
- Start a new Activity to view the login form.
- Start Service to download files in the background.
2. Intent Implicit
Intent Implicit is used when you want to ask the Android system to select the most appropriate component based on the actions or data types you specify.
How It Works:
You specify the actions (such as ACTION_VIEW) and data (such as URIs or MIME types) that you want to process. The Android system will look for a component that can handle the request.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(“https://www.example.com”));
startActivity(intent);Usage Example:
- Open the URL in the user’s default browser.
- Share text or images to other apps (such as social media or email).
- Select the app to open the PDF file.
The Difference Between Explicit and Implicit Intent
| Aspects | Explicit Intent | Implicit Intent |
| Purpose | Calls specific components in the application. | Prompting the system to select the appropriate component. |
| Use | Used for internal navigation of the application. | Used to interact with other applications or system components. |
| Example | Start the product details activity. | Open the URL in a browser or share content. |
Examples of Using Intent in Apps
1. E-commerce Apps:
- Explicit Intent: Starts Activity product details when the user clicks on an item in the product list.
- Implicit Intent: Share product details to social media apps or emails.
2. Social Media Apps:
- Explicit Intent: Starts a comment Activity when the user clicks the “View Comments” button.
- Implicit Intent: Opens an external link in the user’s default browser.
3. Music Apps:
- Explicit Intent: Starts Service to play a song in the background.
- Implicit Intent: Share songs to other apps like WhatsApp or Instagram.
4. Broadcast Receiver: Responding to System Changes
Broadcast Receiver is an essential component in an Android app that allows your app to respond to Broadcast Intent sent by the Android system or other apps. Broadcast Intent is a system message that informs you about a change in status or a specific event, such as a change in battery status, network connectivity, or an incoming SMS message.
By using Broadcast Receiver, you can create apps that are more responsive to changes in the environment or system, thus providing a better user experience.
How Broadcast Receiver Works
Broadcast Receiver runs in the background and has no user interface. They are designed to respond to Broadcast Intent quickly and efficiently. Here are some key points about how Broadcast Receiver works:
1. Registration:
- Broadcast Receiver must be registered to the Android system to respond to Broadcast Intent.
- Registration can be done either static (via AndroidManifest.xml) or dynamic (via program code).
Example of static registration in AndroidManifest.xml:
<receiver android:name=“.MyBroadcastReceiver”>
<intent-filter>
<action android:name=“android.intent.action.BATTERY_LOW” />
</intent-filter>
</receiver>Example of dynamic enrollment in code:
IntentFilter filter new IntentFilter(Intent.ACTION_BATTERY_LOW);
MyBroadcastReceiver receiver new MyBroadcastReceiver();
registerReceiver(receiver, filter);2. Limited Execution Time:
- Broadcast Receiver only had about 5 seconds to complete the task.
- If a task takes longer, such as downloading data or processing files, we recommend that you start Service or use WorkManager.
3. Doable Tasks:
- Send Notifications: Notify users of status changes, such as low battery or internet connections.
- Start Service: Start Service to perform background tasks, such as data synchronization.
- Update Data: Update local data or send data to a server.
Types of Broadcast Intent
Broadcast Intent can be divided into two types:
1. Normal Broadcast:
- Sent asynchronously to all registered Broadcast Receiver.
- Example: ACTION_BOOT_COMPLETED (sent when the device finishes booting).
2. Ordered Broadcast:
- Sent sequentially to one Broadcast Receiver at a time.
- Broadcast Receiver can modify the results or stop the spread of Broadcast Intent.
- Example: ACTION_NEW_OUTGOING_CALL (sent when a user makes an outbound call).
Examples of Broadcast Receiver Usage
1. Responding to Battery Changes:
- Broadcast Receiver can detect when the device’s battery is low (ACTION_BATTERY_LOW) or is charging (ACTION_BATTERY_OKAY).
- Example: Sending a notification to the user when the battery is low.
2. Responding to Network Connectivity Changes:
- Broadcast Receiver can detect changes in internet connection (ACTION_CONNECTIVITY_CHANGE).
- Example: Displays a message when a device loses an internet connection.
3. Responding to Incoming SMS Messages:
- Broadcast Receiver can detect incoming SMS messages (ACTION_SMS_RECEIVED).
- Example: Display notifications or process SMS messages automatically.
5. Service: Background Process Without UI
Service is an essential component in an Android app that allows you to run tasks in the background without a user interface. Service is ideal for tasks that need to continue running even when the app is down, such as streaming music, data syncing, or location updates.
By using Service, you can ensure that your app continues to function properly even when users aren’t interacting directly with the app.
Types of Service
Service can be divided into two main types:
1. Started Service
Started Service is a type of Service that is started by another component, such as Activity or Broadcast Receiver, and will continue to run until the task is completed.
How It Works:
- Started Service starts by calling the startService() method.
- Service will run in the background until the task is completed or stopped manually.
- Once the task is complete, the Service will stop automatically.
Example code:
Intent intent = new Intent(this, MyStartedService.class);
startService(intent);2. Bound Service
Bound Service is a type of Service that binds to other components, such as Activity or Fragment, and will run as long as those components are active.
How It Works:
- Bound Service starts by calling the bindService() method.
- Service will run as long as there are components attached to it.
- If all components release the bond, the Service will stop automatically.
Example code:
Intent intent = new Intent(this, MyBoundService.class);
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);The Difference Between Started Service and Bound Service
| Aspects | Started Service | Bound Service |
| How to Get Started | Starting with startService(). | Starting with bindService(). |
| Duration | Runs until the task is completed or stopped. | Runs as long as there are components attached. |
| Communication | Unable to communicate directly with other components. | Can communicate directly with bonded components. |
| Usage Examples | Music streaming, data syncing. | Music player, real-time communication. |
Examples of Service Usage in Applications
1. Music Apps:
- Started Service: Play music in the background when the app is inactive.
- Bound Service: Control the playback of music from Activity or Fragment.
2. Sports Apps:
- Started Service: Tracks the user’s location while running or cycling.
- Bound Service: Displays real-time location and speed data on the Activity.
3. Chat App:
- Started Service: Send and receive messages in the background.
- Bound Service: Displays new messages in real-time on Activity.
6. Content Provider: Data Sharing Between Applications
Content Provider is an essential component in Android apps that allows apps to share data with other apps. By using Content Provider, you can give access to your app’s data, such as contact lists, media files, or databases, to other apps.
Content Provider also allows your app to access data from other apps, such as accessing a user’s contact list or photo gallery.
How to Use Content Provider
Content Provider provides a standardized interface for accessing and manipulating data. Data is accessed via URI (Uniform Resource Identifier) defined by the Content Provider.
1. Accessing Data from Content Provider
To access data from the Content Provider, you need to use the appropriate ContentResolver and URI.
Example of accessing a contact list:
Uri uri = ContactsContract.Contacts.CONTENT_URI;
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
if (cursor != null) {
while (cursor.moveToNext()) {
String name cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
Log.d(“Contact”, name);
}
cursor.close();
}2. Adding, Modifying, or Deleting Data
You can also add, change, or delete data through Content Provider using ContentResolver.
Adding Data:
ContentValues values = new ContentValues();
values.put(ContactsContract.Contacts.DISPLAY_NAME, “John Doe”);
Uri newContactUri = getContentResolver().insert(ContactsContract.Contacts.CONTENT_URI, values);Changing Data:
ContentValues values = new ContentValues();
values.put(ContactsContract.Contacts.DISPLAY_NAME, “Jane Doe”);
getContentResolver().update(ContactsContract.Contacts.CONTENT_URI, values, null, null);Deleting Data:
getContentResolver().delete(ContactsContract.Contacts.CONTENT_URI, null, null);Examples of Content Provider Usage
1. Contact Application:
- Content Provider allows other apps to access the user’s contact list.
- Example: A messaging app uses a Content Provider to select the recipient’s contact.
2. Photo Gallery App:
- Content Provider allows other apps to access photos and videos stored on the device.
- Example: A social media app uses a Content Provider to select photos to upload.
3. Calendar App:
- Content Provider allows other apps to access schedules and events on the user’s calendar.
- Example: A reminder app uses a Content Provider to add events to the calendar.
7. Application Manifest: Glue That Holds Applications Together
Application Manifest is an XML file that serves as a “glue” that holds all the components of an Android app together. This file defines the structure of the application, including Activity, Service, Broadcast Receiver, and Content Provider, as well as the permissions required by the application.
The Important Role of Application Manifest
1. Defining Application Components:
- Activity: Defines the screen or user interface.
- Service: Define the background process.
- Broadcast Receiver: Defines the components that respond to system messages.
- Content Provider: Define the mechanism of data sharing.
Example of Activity definition in AndroidManifest.xml:
<activity android:name=“.MainActivity”>
<intent-filter>
<action android:name=“android.intent.action.MAIN” />
<category android:name=“android.intent.category.LAUNCHER” />
</intent-filter>
</activity>2. Declare Permission:
- Android apps require permission to access certain features, such as camera, location, or the internet.
- This permit was declared in AndroidManifest.xml.
Example of a permission declaration:
<uses-permission android:name=“android.permission.CAMERA” />
<uses-permission android:name=“android.permission.INTERNET” />3. Defining Application Metadata:
- Application Manifest also contains information such as app name, icon, theme, and version.
Example of app metadata:
<application
android:name=“.MyApplication”
android:icon=“mipmap/ic_launcher”
android:label=“string/app_name”
android:theme=“style/AppTheme”>
</application>8. Application Resources: Assets for User Interface
The Android app stores resources such as strings, images, fonts, and UI layouts in the /res directory. These resources are managed separately from the program code, allowing you to easily customize the app for different devices, languages, and screen orientations.
Types of Resources
1. String: Text used in the app, such as titles, messages, or labels.
Stored in res/values/strings.xml.
Example:
<string name=“app_name”>My App</string>
<string name=“welcome_message”>Welcome to My App!</string>2. Images: Visual assets such as icons, background images, or illustrations.
Stored in res/drawable/ or res/mipmap/.
Examples: ic_launcher.png, background.jpg.
3. (Layout) Layout: An XML file that defines the structure of the user interface.
Stored in res/layout/.
Examples: activity_main.xml, fragment_detail.xml.
4. Color: The definition of the color used in the application.
Stored in res/values/colors.xml.
Example:
<color name=“primary_color”>6200EE</color>
<color name=“secondary_color”>03DAC6</color>5. Dimensions: The size and padding used in the layout.
Stored in res/values/dimens.xml.
Example:
<dimen name=“padding_small”>8dp</dimen>
<dimen name=“text_size_large”>24sp</dimen>Accessing Resources through Class R
When an app is compiled, Android automatically generates an R class that contains references to all resources defined in the /res directory. You can access these resources through the R class in the program code.
Example of Accessing Strings:
String appName = getString(R.string.app_name);Example of Accessing Images:
ImageView imageView = findViewById(R.id.my_image_view);
imageView.setImageResource(R.drawable.ic_launcher);Example of Accessing a Layout:
setContentView(R.layout.activity_main);Conclusion
By understanding the key components like Activity, Fragment, Intent, and Service, you can build more efficient, modular, and manageable Android apps. Each component has a specific role that allows the app to function properly, both in the foreground and in the background.
Additionally, components such as Broadcast Receiver and Content Provider allow your app to respond to system changes and share data with other apps.
By leveraging Application Manifest and Application Resources, you can define the structure of your application and manage assets such as strings, images, and layouts in a more organized way.

