Tag

xml

Browsing

3 Things You Must Need To Know : Jetpack Compose vs XML

Let’s compare Jetpack Compose vs XML.

Before that I need to tell you something.

When Kotlin arrived, I searched the whole internet to decide: should I learn Kotlin or not?
Back then, some posts convinced me that learning Kotlin would give me a strong advantage as an Android developer.

And they were right.

Now, for anyone searching the internet and wondering whether to learn Jetpack Compose, here’s my answer:

1. Performance

live edit in jetpack compose vs XML
I will start with my favorite part about Jetpack Compose – Live edit.

Why its my favorite?

This one really improved my productivity.

If you did a simple layout change,You dont need to restart the whole application, it just reloads direct in your emulator or real devices. But it still evolving, so sometimes it faces issues with larger projects.

XML lacks this feature due to its imperative UI paradigm and Android view system.

Language Support

Jetpack compose is defined for Kotlin, so if you want to use compose, then you need to write kotlin code. As for now, i don’t seem any plan with java.

XML works well with both languages, so choice of language is not a barrier.

Rendering layouts

When it comes to rendering layouts, XML perform better for static layouts, but less efficient for complex layouts, because findViewById and binding calls make difficult. But compose is better for complex UIs because it only renders the specific part of the UI that needs to be changed.

Resource Utilization

XML need more effort when rendering complex layout ui. on the other side Jetpack Compose efficiently manage recompositions, but triggering unnecessary recomposition can lead to inefficiencies.

Preview support

Both have built in preview support in Android Studio.
In XML, android studio – we can easily drag and drop our views wherever we want. it make begginer effort less. So that doesn’t end here. Compose also has a nice preview system, renders preview more efficiently than XML.

2. Support

Community

Jetpack Compose is relatively new, but its community is growing day by day. But for XML, already a huge community out there. as you know, it comes from api level 1. So most of the code are around with XML. Most of the questions you will face will already answered by someone in stackoverflow, reddit or any other site in google. compose not in a long way, they also quickly closing the gap.

Devices Support

Jetpack Compose will not work below api level 21(lolipop), to support running below api 21, then you need to use XML. But however, number of running devices below api 21 is very low. If you are migrating from XML to Compose. sometimes, it might be difficult for larger projects. so you can go for a hybrid approach. such as using compose code in xml.

Using composeView, you can add compose inside XML.

3. Learning curve

i. Beginner

If you are new to android, learning curve for Jetpack Compose feels natural. if you are a beginner in android, but also familiar with Flutter or react native, then it will reduce the intensity of your learning process. However XML may seem easy at first glance, you can quickly understand each tag and its properties, how they work.

XML has abundance of tutorials, books and documentation, making it sufficient for beginner to learn. For compose, developers are creating more tutorials and vlogs, which increases the resources and reduce the gap.

ii. Already an android developer

It become moderate to you, if you are learning compose and also compose not that much documentation or abundance of tutorials out there. So sometimes, you may need to troubleshoot some issues your self.

for XML, there is lot of boilerplate code, also need to switch to java/kotlin code for functionality. For compose, that you can simply do in Kotlin, but must have a better knowledge in Kotlin.

Jetpack Compose vs XML – Summary

Its better to start learning Jetpack compose because that’s the future and it also make app development more productive. But still XML is in the ground, so you can not avoid that. if you are a beginner, most of the projects are in xml, its better to learn xml first, but many companies also hire people with compose due to new projects. so final part, its beneficial to know the basics of xml and go for Jetpack Compose.