On this page
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
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.
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent { AppTheme { AppNavHost() } } // all screens are composables
}
}<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: 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:
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)
}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:
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?
| Need | Use | Avoid |
|---|---|---|
| A screen | A composable inside your single Activity | An Activity per screen in new apps |
| Sync data every few hours | WorkManager periodic work | A background Service with alarms |
| Play audio with the screen off | Foreground service (media playback type), Media3 | An unrestricted background service |
| React to network changes in the UI | ConnectivityManager callbacks as a Flow | A manifest CONNECTIVITY_CHANGE receiver |
| Share a file with another app | FileProvider | file:// 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.
Walzi4K wallpapers for lock and home screenGet it โธ
NotiVaultNotification history: recover dismissed notificationsGet it โธ
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.