
“Somewhere, in the wild, a developer is still bravely typing
FragmentTransaction.beginTransaction(). If that’s you—step into the light, my friend.”
🎬 Flashback: The Golden Age of Fragments
Let’s hop into the DeLorean and head back a few Android versions. You remember:
- Writing endless
onCreateViewandonDestroyView - Arguing with FragmentManager like it’s a government official
- Bundles, transactions, lifecycle limbo…
If you survived this era, you deserve a badge. But is it still the best way? Spoiler: Nope.
🤔 Then vs Now: How We Used Fragments (and How Compose Does It Better)
Let’s break it down! Here are the classic ways we used fragments, and how Compose does each one today — with code you’ll actually want to read.
1. Navigating Between Screens
THEN (Fragments):
// Launching a new Fragment (in 4 lines... minimum)
val fragment = DetailsFragment()
fragment.arguments = Bundle().apply { putString("id", someId) }
parentFragmentManager.beginTransaction()
.replace(R.id.container, fragment)
.addToBackStack(null)
.commit()
And then you prayed it didn’t crash on rotation.
NOW (Compose):
NavHost(navController, startDestination = "home") {
composable("home") { HomeScreen() }
composable("details/{id}") { backStackEntry ->
DetailsScreen(id = backStackEntry.arguments?.getString("id"))
}
}
It’s like switching from Morse code to WhatsApp.
2. Dialogs and Bottom Sheets
THEN (Fragments):
val dialog = MyDialogFragment() dialog.show(parentFragmentManager, "tag")
Don’t forget to implement DialogFragment, override onCreateDialog, and deal with lifecycle quirks. Enjoy!
NOW (Compose):
if (showDialog) {
AlertDialog(
onDismissRequest = { showDialog = false },
title = { Text("Hello!") },
text = { Text("Compose Dialogs are easy.") },
confirmButton = { Button(onClick = { showDialog = false }) { Text("OK") } }
)
}
No managers, no fragments, just composables. That’s it. Dialog done.
3. ViewPager & Tabs
THEN (Fragments):
class PagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {
// Return different Fragments per tab
}
viewPager.adapter = PagerAdapter(supportFragmentManager)
You’d fight with lifecycle, state, and the adapter gods.
NOW (Compose):
val tabs = listOf("Home", "Profile")
TabRow(selectedTabIndex = selectedTab) {
tabs.forEachIndexed { index, title ->
Tab(selected = selectedTab == index, onClick = { selectedTab = index }) {
Text(title)
}
}
}
when (selectedTab) {
0 -> HomeTab()
1 -> ProfileTab()
}
Tabs are just composables — no adapters, no fragments, no headaches.
4. Multi-pane / Tablet Layouts
THEN (Fragments):
// Master-Detail with Fragment transactions, two containers, device checks...
if (isTablet) {
// Show master and detail fragments side by side
} else {
// Navigate fragments single-pane
}
Debugging orientation changes was your new hobby.
NOW (Compose):
Row {
MasterList(onItemSelected = { selectedId = it })
if (selectedId != null) {
DetailScreen(id = selectedId)
}
}
Compose layouts adapt naturally — just like you wish your code always did.
5. Passing Data Between Screens
THEN (Fragments):
val fragment = DetailsFragment()
fragment.arguments = Bundle().apply { putString("userId", userId) }
Then on the other side, extract it with arguments?.getString(“userId”). Hope you didn’t typo the key!
NOW (Compose):
navController.navigate("details/$userId")
// And receive as: DetailsScreen(id = backStackEntry.arguments?.getString("id"))
You pass data like a regular function. No Bundles. No drama.
Job Offers
😅 Why Did We Do This to Ourselves?
Because, back then, Fragments were the best tool for the job.
But it’s 2025! We have better tools now. Like giving up your old dial-up modem for fiber internet.
🚀 Compose in 2025: How the Cool Kids Build Android UIs
- No more extending Fragment.
- No more XML layouts.
- No more FragmentManager mystery errors.
- Just Composables, Navigation Compose, and a happy life.
🤡 Fragment Excuses I’ve Actually Heard (And How I Respond)
“My senior likes fragments.”
My reply: My senior also liked VHS tapes, but I stream Netflix.“What if I need modularity?”
Compose functions ARE modular. And you can use feature modules if you miss building flavors.“It’s just one dialog, let’s use DialogFragment.”
Let’s not. It’s 2025. Compose dialogs are easier than making Maggi.
🧑💻 Key Takeaways for the Pragmatic Dev
- If you’re starting new, don’t use fragments.
- If you’re stuck with legacy, use Compose in Fragments while you migrate.
- Compose gives you cleaner code, less boilerplate, and way fewer “what just happened?” moments.
🎉 Final Thoughts
Fragments gave us flexibility, but they also gave us headaches.
Compose gives us freedom, fun, and focus.
If you’re still starting new features with fragments in 2025… buddy, it’s time to update your toolkit — and maybe your memes.
Still got a “fragment horror story”? Drop it in the comments! Smash that clap button, share with your team’s “fragment enthusiast,” and welcome to the future of Android UI.
This article was previously published on proandroiddev.com



