๐ŸŒฑ Android Development for Beginners

Android App Components: Activities, Services, and Receivers

Android apps don't have a single main() function. The system starts your app through four kinds of components declared in the manifest. Knowing what each one is for, and what replaced the old patterns, prevents crashes, battery drain and security holes.

โœ๏ธ Yunok Tech ๐Ÿ“… Updated โฑ 4 min read ๐ŸŽฏ Beginner
On this page
  1. The four components at a glance
  2. Activities: screens the user interacts with
  3. Intents: messages between components
  4. Services: work without a UI
  5. Broadcast Receivers: reacting to events
  6. Content Providers: sharing data
  7. Which component should I use?
  8. Common mistakes
  9. Frequently asked questions
  10. Conclusion

A console program starts at main() and runs until it ends. An Android app is different. The system can enter it from many doors: the launcher icon, a notification, a shared photo, a scheduled job, another app asking for data. Those doors are app components.

This guide explains the four component types, how intents connect them, how the manifest declares them, and which modern APIs you should use instead of patterns that are now discouraged.

The four components at a glance

The four Android app components and their entry points The Android system can enter an app through an Activity for a screen the user sees, a Service for long-running work, a Broadcast Receiver for system-wide events, and a Content Provider for sharing structured data. All are declared in AndroidManifest.xml. Android system Activitya screen / UI entrylauncher, deep link Servicework without UIe.g. music playback Broadcast Receiverreacts to eventse.g. boot, locale Content Providershares datae.g. FileProvider All four are declared in AndroidManifest.xml
Each component is an independent entry point the system can start, possibly in a fresh process.

Activities: screens the user interacts with

An Activity provides a window for UI. Modern apps commonly use a single-Activity architecture: one Activity hosts Jetpack Compose, and navigation between screens happens inside Compose rather than by launching new Activities.

MainActivity.ktKotlin
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent { AppTheme { AppNavHost() } }   // all screens are composables
    }
}
AndroidManifest.xml (excerpt)XML
<activity
    android:name=".MainActivity"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

android:exported="true" lets other apps, including the launcher, start this Activity. Since Android 12, any component with an intent filter must declare exported explicitly.

Intents: messages between components

Explicit and implicit intentsKotlin
// Explicit: start a specific component in your app
startActivity(Intent(context, SettingsActivity::class.java))

// Implicit: ask the system for any app that can handle an action
val share = Intent(Intent.ACTION_SEND).apply {
    type = "text/plain"
    putExtra(Intent.EXTRA_TEXT, "Check out this article: https://yunoktech.com/android/")
}
startActivity(Intent.createChooser(share, "Share via"))

Services: work without a UI

A Service runs work that isn't tied to a screen. Modern Android restricts background execution heavily to protect battery, so plain background services are rarely appropriate. Today's guidance:

  • User-visible ongoing work (music playback, navigation, an active call, a workout): a foreground service with a notification and a declared foreground service type. See Foreground Services.
  • Deferrable, guaranteed work (sync, uploads, cleanup): WorkManager. See Background Work with WorkManager.
  • Work that only matters while the user is on screen: coroutines in viewModelScope, with no Service needed.

Broadcast Receivers: reacting to events

A BroadcastReceiver responds to system or app events, such as the device finishing boot, a locale change or a download completing. Since Android 8, most implicit broadcasts can't be received by manifest-declared receivers. Register them at runtime while your app is active instead:

Runtime-registered receiverKotlin
class BatteryMonitor(private val context: Context) {
    private val receiver = object : BroadcastReceiver() {
        override fun onReceive(context: Context, intent: Intent) {
            val level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)
            Log.d("Battery", "Level: $level")
        }
    }

    fun start() = ContextCompat.registerReceiver(
        context, receiver,
        IntentFilter(Intent.ACTION_BATTERY_CHANGED),
        ContextCompat.RECEIVER_NOT_EXPORTED,     // don't accept broadcasts from other apps
    )

    fun stop() = context.unregisterReceiver(receiver)
}
Keep onReceive short

onReceive() runs on the main thread and must finish quickly. For longer work, enqueue a WorkManager job.

Content Providers: sharing data

A ContentProvider exposes data to other apps through content:// URIs with fine-grained permissions. Most apps never write one, but nearly all use FileProvider to share files securely, for example sending a photo to a camera app or a PDF to an email app:

Share a file securelyKotlin
val file = File(context.cacheDir, "invoice.pdf")
val uri = FileProvider.getUriForFile(context, "${context.packageName}.fileprovider", file)
val intent = Intent(Intent.ACTION_SEND).apply {
    type = "application/pdf"
    putExtra(Intent.EXTRA_STREAM, uri)
    addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)   // temporary access just for this file
}
context.startActivity(Intent.createChooser(intent, "Send invoice"))

Which component should I use?

NeedUseAvoid
A screenA composable inside your single ActivityAn Activity per screen in new apps
Sync data every few hoursWorkManager periodic workA background Service with alarms
Play audio with the screen offForeground service (media playback type), Media3An unrestricted background service
React to network changes in the UIConnectivityManager callbacks as a FlowA manifest CONNECTIVITY_CHANGE receiver
Share a file with another appFileProviderfile:// URIs (blocked on modern Android)

Common mistakes

  • Exporting components unnecessarily. Every exported component is an attack surface. Set exported="false" unless other apps must reach it.
  • Long work in onReceive(), causing ANRs.
  • Using Services for periodic background work instead of WorkManager.
  • Passing large objects in intent extras, which can crash with TransactionTooLargeException. Pass IDs instead.

Frequently asked questions

Is a Fragment an app component?

No. Fragments are UI building blocks hosted inside an Activity, and the system can't start them directly. In Compose apps, composables usually replace Fragments.

Is the Application class a component?

Not one of the four, but it's created before any component in your process and is often used for app-wide setup.

Do I still need multiple Activities?

Sometimes: for distinct entry points such as a share target or a settings screen launched from system settings. Most navigation can live in one Activity.

What replaced IntentService and JobIntentService?

WorkManager for deferrable work, and coroutines for work tied to the UI. Both older classes are deprecated.

Conclusion

Android enters your app through four doors: Activities (UI), Services (ongoing work), Broadcast Receivers (events) and Content Providers (data sharing), connected by intents and declared in the manifest. Modern apps use one Activity with Compose, WorkManager for background work, and FileProvider for sharing, and they export as little as possible.

Next step: open your app's manifest and check every exported attribute. Then read Background Work with WorkManager.

Official references

๐Ÿ“ฑ Apps built by Yunok Tech

Real Android apps on Google Play, free to download.

See all our apps โ†’

Ready to build real Android applications?

Reading a roadmap is the easy part. The real progress happens when you build a foundation step by step, with someone reviewing your code and answering the questions that come up along the way.

Move beyond theory and strengthen your Android development skills with Yunoktech's Android course. Learn core concepts, practical implementation, modern Android development techniques, and the reasoning behind building maintainable applications.

Explore the Android course and take your next step as an Android developer.

Share: LinkedIn X / Twitter WhatsApp