Android Components:
The Big Picture
The core players behind every Android app — Activities, Services, Intents, Fragments, Broadcast Receivers, and Content Providers.
What Are Android Components?
Android components are the core players that make up every Android app. Unlike other platforms, Android doesn't have a single main() function as a starting point — the system launches components based on user actions or system events.
Activities: The Building Blocks of UI
An Activity represents a single screen with which users can interact. Every distinct UI screen in an Android app — a login form, a gallery view, a settings page — is typically part of an Activity. They act as entry points for user interactions.
Activity Lifecycle
The Activity lifecycle dictates how an Android app responds to changes like incoming calls, navigating away, or device rotation. Managing state during these callbacks is vital for a smooth user experience.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Initialize UI and variables here
}
override fun onPause() {
super.onPause()
// Save state before losing focus
}
}
Intents: Messages Between Components
Intents are Android's messaging system that lets components communicate with each other — even across different apps. They are essential for navigating between screens and requesting actions.
val intent = Intent(this, DashboardActivity::class.java)
startActivity(intent)
// Implicit Intent — open a URL in any browser
val webIntent = Intent(Intent.ACTION_VIEW,
Uri.parse("https://example.com"))
startActivity(webIntent)
Fragments: Reusable UI Modules
A Fragment is like a miniature Activity — a portion of UI that can be reused across different activities. It has its own lifecycle, manages its own layout, and is especially powerful on larger devices like tablets with dual-panel layouts.
- Independent entry point
- Managed by the OS
- One Activity per screen
- Heavier lifecycle
- Must be hosted by Activity
- Reusable across screens
- Multiple per Activity
- Flexible & modular
Fragment Lifecycle
Fragments have lifecycle callbacks similar to Activities, but slightly more complex due to their dependency on the host Activity:
onAttach() // Fragment attached to Activity
onCreateView() // Inflate the fragment's layout
onStart() // Fragment becomes visible
onPause() // User leaves the fragment
onDestroyView() // View hierarchy removed
Services: Background Champions
Services are components that perform long-running tasks in the background without a user interface — music playback, data sync, or handling uploads. They keep working even after the user navigates away.
Broadcast Receivers: Event Listeners
Broadcast Receivers are Android's way of listening for and responding to system-wide or app-specific events. When the specified event occurs, Android delivers a broadcast Intent to all matching receivers.
Content Providers: Shared Data Managers
When an Android app needs to share structured data with other apps — such as contacts or media — the system uses Content Providers. They offer a standard API to query, insert, and update data, accessible to other apps with proper permission.
val cursor = contentResolver.query(
ContactsContract.Contacts.CONTENT_URI,
null, null, null, null
)
cursor?.use {
while (it.moveToNext()) {
// Process each contact row
}
}
Topics covered in this unit:
Conclusion
Android components are the foundation of every Android application. By mastering Activities, Lifecycle handling, Intents, Fragments, Services, Broadcast Receivers, and Content Providers, you unlock the ability to build feature-rich, responsive, and scalable apps.
Each component has a unique purpose. Understanding how they interact enables you to architect clean, efficient, and maintainable applications.
"Understanding how components connect
is what separates good apps from great ones."

0 Comments
If you have any doubts, Please let me know