Getting to Know Android App Structures: Activities, Fragments, and Broadcast Receivers

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.

Android Application Structure

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.

Latest Articles