Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Understanding Anatomy of Android Application

· 6 min read · Home Tech

In this article
  1. What Are the Four Core Components of an Android App?
  2. What Does the AndroidManifest.xml Do?
  3. How Does the Build System and App Package Work?
  4. What Are the Common Patterns for Structuring an Android App?

The anatomy of an Android application is the structure of its core components—activities, services, broadcast receivers, and content providers—plus the manifest, resources, and build files that tie them together. Understanding this anatomy matters because every Android app, from a simple utility to a complex game, is built from these same parts, and knowing how they interact is the first step to building or debugging any app.

Quick answer: An Android app is made of four component types (activity, service, broadcast receiver, content provider), a manifest file, resources, and a build system.

What Are the Four Core Components of an Android App?

Each component serves a distinct role, and the system can start them independently. Here is what each one does:

ComponentPurposeExample
ActivityProvides a user interface (UI) screen. It is the entry point for user interaction.A login screen, a settings page, a map view.
ServiceRuns background work without a UI, such as playing music or downloading a file.A music player service that keeps playing when the app is in the background.
Broadcast ReceiverListens for system-wide or app-specific announcements (e.g., battery low, screen off, network change).An app that turns on Wi-Fi when the device connects to a charger.
Content ProviderManages shared data, allowing other apps to query or modify data with permissions.The Contacts app's provider that other apps use to read contact info.

Every app must declare its components in the AndroidManifest.xml file. The manifest is the app's blueprint—it lists permissions, hardware features, and which component is the launcher activity (the first screen that appears when the app icon is tapped).

How Do Components Talk to Each Other?

Components communicate through intents. An intent is a message object that requests an action from another component, either within your app or from another app. For example, an activity can send an intent to start a service, or a broadcast receiver can receive an intent that announces the battery is low. Intents can be explicit (naming the target component) or implicit (describing the action, letting the system find a matching app).

What Does the AndroidManifest.xml Do?

The manifest is a mandatory XML file in every app's root directory. It tells the Android system about your app before any code runs. Key elements include:

  • Package name (the unique application ID, e.g., com.example.myapp).
  • Components (activities, services, receivers, providers) with their intent filters.
  • Permissions the app needs (e.g., INTERNET, CAMERA, READ_CONTACTS).
  • Hardware/software features the app requires (e.g., a camera, a touchscreen).

For example, to declare a main activity that appears when the app is launched, you add an <activity> tag with an intent filter that includes MAIN and LAUNCHER actions. The manifest also declares the app icon and label that appear on the device's home screen.

What Are Resources and How Are They Organized?

Resources are non-code files that your app uses, such as images, strings, layouts, and colors. They live in the res/ directory and are organized by type:

  • res/layout/ – XML files that define UI layouts (e.g., activity_main.xml).
  • res/values/ – XML files for strings, colors, dimensions, and styles (e.g., strings.xml).
  • res/drawable/ – images and vector graphics.
  • res/mipmap/ – launcher icons at various densities.

Resources allow you to separate content from code, which makes it easier to support multiple languages (via values-fr for French) and screen sizes (via layout-large for tablets). At build time, the resource compiler generates an R class that provides integer IDs for each resource, so your code can reference them like R.layout.activity_main.

How Does the Build System and App Package Work?

Modern Android apps are built with Gradle, a build automation tool. The build process compiles your Java/Kotlin code, merges resources, and packages everything into an APK (Android Package) file—the installable format. The APK contains the compiled code (in a classes.dex file), resources, the manifest, and native libraries. For distribution through the Google Play Store, the APK is often signed and zipped into an AAB (Android App Bundle) that optimizes delivery per device.

Here are the essential build files you'll see in any Android project:

  • build.gradle (project-level) – defines repositories and plugin versions.
  • build.gradle (module-level) – defines the app's dependencies, SDK versions, and build types (debug/release).
  • settings.gradle – lists all modules in the project.

When you run the app from Android Studio, Gradle compiles the code, packages the APK, installs it on the emulator or device, and launches the launcher activity. The build system also handles resource shrinking and code obfuscation (via R8) for release builds.

What Is the App's Lifecycle and Why Does It Matter?

Each component has a lifecycle—a set of states it moves through as the user interacts with the app. For activities, the key states are onCreate(), onStart(), onResume(), onPause(), onStop(), and onDestroy(). Understanding this lifecycle is crucial because the system can kill your activity to free memory, and you must save and restore UI state accordingly. For example, you save data in onSaveInstanceState() and restore it in onCreate() when the activity is recreated after a rotation.

Services have a simpler lifecycle (onCreate(), onStartCommand(), onDestroy()), and broadcast receivers have only onReceive(). Content providers are created when the app process starts and live until the process is killed.

What Are the Common Patterns for Structuring an Android App?

While the four components are the core anatomy, modern apps often follow architectural patterns to keep code maintainable. The most common is Model-View-ViewModel (MVVM), where:

  • Model – represents data and business logic (e.g., a repository that fetches data from a database or network).
  • View – is the UI (activities and fragments) that displays data and sends user actions.
  • ViewModel – holds UI-related data and survives configuration changes, exposing it via LiveData or StateFlow.

Another key pattern is single-activity architecture, where the app has one activity and multiple fragments for different screens. This reduces the complexity of activity lifecycles and makes navigation easier with the Navigation component.

You also need to understand the app's thread model: the main (UI) thread handles all UI updates and must not be blocked with network or disk operations. Long-running tasks should run on background threads, using coroutines or the WorkManager API for deferrable work.

What Should You Learn Next After Understanding the Anatomy?

Once you grasp the components and manifest, the next logical step is to build a simple app that uses each component. Start with a single activity and a layout, then add a service for background music, a broadcast receiver for connectivity changes, and a content provider to share data with other apps. Use Android Studio's project templates to see how the pieces fit together.

Also, read the official Android documentation on App fundamentals—it covers the same anatomy in more depth and includes code samples. The best way to solidify your understanding is to open an existing open-source app and trace how its manifest, resources, and components interact.

For a deeper dive, explore these follow-up questions:

  • How do fragments fit into an activity's anatomy?
  • What is the difference between a started service and a bound service?
  • How do you declare a custom permission in the manifest?
  • What is the role of the Application class in the app's lifecycle?