Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you migrate to Jetpack Compose when you have a lot of Fragments?

I would like to migrate to Jetpack Compose, but I don't know where to begin. My app uses single Activity / multiple Fragments, and there at least 100 Fragments. The app's navigation graph is in XML, which I understand does not support Composables.

Please let me know if this sounds like the correct path.

  1. Modify each Fragment so that it hosts a single ComposeView that will contain the screen's UI
  2. Once completed, convert each Fragment to a Composable
  3. Replace the navigation graph with Jetpack Compose navigation

Once this is done, there will be no Fragments in the app. Not sure what to do with my Activity. Should that be replaced as well?

This will take forever, but I just wanted to make sure there is no other alternative. Thanks!

like image 312
Marty Miller Avatar asked Oct 18 '25 06:10

Marty Miller


1 Answers

Aside from the Blog post I linked in the comment (which has useful other links in the matter), there are multiple ways to approach this.

What you described is a valid approach.

Now as for:

Not sure what to do with my Activity. Should that be replaced as well?

You need at least 1 activity if I am not mistaken, so you can't get rid of all. If you already use one, then you are there already. You can probably get rid of all the fragment/glue code and have it as a container for your first composable logic/wiring and then be free.

like image 85
Martin Marconcini Avatar answered Oct 19 '25 20:10

Martin Marconcini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!