Jetpack Compose and the fall of Fragments


This article is about how to structure your App using Jetpack Compose.

Fragments are dead, what’s replacing them?

In today’s Android world (yet Compose is still beta), we architecture our apps with the following hierarchy:

- ActivityA
- Fragment1 + ViewModel1
- Fragment2 + ViewModel2
- ActivityB
- Fragment3 + ViewModel3
  • View
  • ViewModel
- ActivityA
- ComposableScreen1View(ViewModel1)
- ComposableScreen2View(ViewModel2)
Activity.ktprivate val screen1ViewModel: Screen1ViewModel by viewModels()
fun ComposableFunctionScreen1View(viewModel: Screen1ViewModel = getViewModel())

Where do I put all these Composable functions?

That’s a fair question. You could be tempted to put everything into the Activity, in fact this is what most people do at the moment. Unfortunately this is not sustainable for big project.

  • navigation can store anything related to the navigation, the transitions for instance.


And that conclude this short article about Jetpack Compose file structure. I hope this has been useful. If you have any thoughts on how we can improve that further, please share your ideas in the comment section :)



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store