<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Krunal Bhatt on Medium]]></title>
        <description><![CDATA[Stories by Krunal Bhatt on Medium]]></description>
        <link>https://medium.com/@krunalbhatt001?source=rss-e8422738ea83------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JGACNWtAM6xuoYMAxrDBTw.jpeg</url>
            <title>Stories by Krunal Bhatt on Medium</title>
            <link>https://medium.com/@krunalbhatt001?source=rss-e8422738ea83------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 03:00:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@krunalbhatt001/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Migrating from XML Layouts to Jetpack Compose: A Step-by-Step Guide for Android Developers (2026)]]></title>
            <link>https://medium.com/@krunalbhatt001/migrating-from-xml-layouts-to-jetpack-compose-a-step-by-step-guide-for-android-developers-2026-333340fa0d3e?source=rss-e8422738ea83------2</link>
            <guid isPermaLink="false">https://medium.com/p/333340fa0d3e</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[xml-migration]]></category>
            <category><![CDATA[google-io-2026]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Krunal Bhatt]]></dc:creator>
            <pubDate>Wed, 03 Jun 2026 14:42:18 GMT</pubDate>
            <atom:updated>2026-06-03T14:43:15.055Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Stop wrestling with nested ViewGroups. Here’s how to migrate your Android app from XML to Jetpack Compose—screen by screen, without burning it down.</em></p><blockquote><em>At Google I/O 2026, Google officially declared Android UI development Compose-first. The XML View system is now in maintenance mode. This guide shows you exactly how to migrate incrementally — with real before/after code for screens, lists, and navigation.</em></blockquote><h3>Why You Need to Migrate from XML to Jetpack Compose Right Now</h3><p>If you’ve shipped Android apps with XML layouts, you know the pain: deeply nested ConstraintLayouts, ViewHolder boilerplate that stretches across 80 lines, and notifyDataSetChanged() calls that feel like duct tape. Jetpack Compose replaces all of that with declarative Kotlin — you describe <em>what</em> the UI should look like given a state, and Compose figures out how to render it.</p><p>Google has been directional about Compose since 2021, but at <strong>Google I/O 2026 they made it official and irreversible</strong>: Android UI development is now <strong>Compose-first</strong>. Any new Android Studio UI tools will be built for Jetpack Compose only, and existing View-based tools like the Layout Editor and Navigation Editor are now in <strong>maintenance mode</strong> and will not receive new features. The same goes for View-based Jetpack libraries — Fragments, RecyclerView, and ViewPager are now considered complete, with only critical bug fixes going forward. Even the design system followed suit: Material Design on Android is now Compose-first as well. And at the tooling layer, all new app generation in Google AI Studio produces Kotlin and Jetpack Compose by default — meaning even AI-generated Android code skips XML entirely.</p><p>This isn’t a nudge anymore. It’s the finish line.</p><p>But migrating an existing app is still rarely a big-bang rewrite. The good news is you don’t have to do it all at once — Compose and the View system coexist well, which means you can migrate <strong>incrementally, one screen and one component at a time</strong>.</p><p>This guide walks you through the migration systematically: from mental model shift to interop, to fully composed screens.</p><h3>What You’ll Learn in This Guide</h3><ul><li>The mental model shift from imperative XML to declarative Compose</li><li>How to add Jetpack Compose to an existing Android project</li><li>How to use ComposeView and AndroidView for gradual migration</li><li>How to migrate a full screen from XML + Fragment to Compose</li><li>How to replace RecyclerView with LazyColumn</li><li>How to move from nav_graph.xml to Navigation Compose</li><li>The most common Compose migration mistakes (and how to avoid them)</li></ul><h3>The Mental Model Shift: From Mutating Views to Describing State</h3><p>Before touching a single line of code, you need to rewire how you think about Android UI.</p><p>In the XML world you <em>inflate</em> a layout, then <em>mutate</em> it:</p><pre>// XML approach — inflate, find, mutate<br>val binding = FragmentProfileBinding.inflate(inflater)<br>binding.tvName.text = user.name<br>binding.ivAvatar.load(user.avatarUrl)<br>viewModel.user.observe(viewLifecycleOwner) { user -&gt;<br>    binding.tvName.text = user.name<br>}</pre><p>In Compose you <em>describe</em> what the UI should look like for a given state, and recomposition handles the rest:</p><pre>// Compose approach — describe, not mutate<br>@Composable<br>fun ProfileScreen(user: User) {<br>    Column(modifier = Modifier.padding(16.dp)) {<br>        AsyncImage(model = user.avatarUrl, contentDescription = null)<br>        Text(text = user.name, style = MaterialTheme.typography.headlineSmall)<br>    }<br>}</pre><p>When user changes, Compose re-executes only the parts of the tree that depend on it. No invalidate(), no DiffUtil, no observer teardown.</p><p><strong>Three key mental shifts when migrating to Compose:</strong></p><ul><li><strong>State drives UI</strong>—the UI is a pure function of state, not a mutable object you reach into</li><li><strong>No view references</strong>—there is no findViewById or binding.something; if you need to &quot;update&quot; UI, update the state</li><li><strong>Layouts are functions</strong> — Column, Row, Box are composable functions, not XML tags</li></ul><h3>Step 1: Add Jetpack Compose to Your Existing Android Project</h3><p>You don’t need a new project. Compose works inside any Activity or Fragment from your existing app.</p><p>Update your build.gradle.kts (app module):</p><pre>android {<br>    buildFeatures {<br>        compose = true<br>        viewBinding = true  // keep this if you still have XML screens<br>    }<br>    composeOptions {<br>        kotlinCompilerExtensionVersion = &quot;1.5.14&quot; // use latest version<br>    }<br>}<br><br>dependencies {<br>    val composeBom = platform(&quot;androidx.compose:compose-bom:2024.06.00&quot;)<br>    implementation(composeBom)<br>    implementation(&quot;androidx.compose.ui:ui&quot;)<br>    implementation(&quot;androidx.compose.material3:material3&quot;)<br>    implementation(&quot;androidx.compose.ui:ui-tooling-preview&quot;)<br>    debugImplementation(&quot;androidx.compose.ui:ui-tooling&quot;)<br>    implementation(&quot;androidx.activity:activity-compose:1.9.0&quot;)<br>    implementation(&quot;androidx.lifecycle:lifecycle-viewmodel-compose:2.8.2&quot;)<br>}</pre><blockquote><strong><em>Pro tip:</em></strong><em> Always use the BOM (Bill of Materials) so all Compose library versions stay in sync automatically. Mismatched Compose versions are one of the most common setup mistakes.</em></blockquote><h3>Step 2: The Interop Bridge—ComposeView and AndroidView</h3><p>Before you migrate an entire screen, you can embed Compose inside your existing XML layouts using ComposeView. This is the safest migration entry point for production apps.</p><h3>Embedding Compose Inside an Existing XML Layout</h3><pre>&lt;!-- fragment_profile.xml — your existing layout with one new Compose island --&gt;<br>&lt;LinearLayout<br>    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:orientation=&quot;vertical&quot;&gt;<br><br>    &lt;!-- Legacy header — not migrated yet --&gt;<br>    &lt;TextView<br>        android:id=&quot;@+id/tvScreenTitle&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:text=&quot;Profile&quot; /&gt;<br><br>    &lt;!-- Compose island for the new card component --&gt;<br>    &lt;androidx.compose.ui.platform.ComposeView<br>        android:id=&quot;@+id/composeView&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot; /&gt;<br><br>&lt;/LinearLayout&gt;</pre><pre>// ProfileFragment.kt<br>class ProfileFragment : Fragment() {<br><br>    private val viewModel: ProfileViewModel by viewModels()<br>    private var _binding: FragmentProfileBinding? = null<br>    private val binding get() = _binding!!<br><br>    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {<br>        _binding = FragmentProfileBinding.inflate(inflater, container, false)<br><br>        binding.composeView.apply {<br>            // Critical: set the correct recomposition strategy<br>            setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)<br>            setContent {<br>                MaterialTheme {<br>                    val uiState by viewModel.uiState.collectAsStateWithLifecycle()<br>                    ProfileCard(user = uiState.user)<br>                }<br>            }<br>        }<br><br>        return binding.root<br>    }<br><br>    override fun onDestroyView() {<br>        super.onDestroyView()<br>        _binding = null<br>    }<br>}</pre><blockquote><strong><em>Warning:</em></strong><em> </em><em>ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed is non-negotiable — without it you&#39;ll get memory leaks when Fragments go through their view lifecycle.</em></blockquote><h3>Embedding a Legacy Android View Inside Compose</h3><p>Sometimes you need the reverse—a custom View (like a MapView or SurfaceView) that hasn&#39;t been ported to Compose yet:</p><pre>@Composable<br>fun LegacyMapWrapper(latLng: LatLng) {<br>    AndroidView(<br>        factory = { context -&gt;<br>            MapView(context).apply {<br>                // one-time setup<br>                onCreate(null)<br>                getMapAsync { map -&gt;<br>                    map.moveCamera(CameraUpdateFactory.newLatLng(latLng))<br>                }<br>            }<br>        },<br>        update = { mapView -&gt;<br>            // called on recomposition when latLng changes<br>            mapView.getMapAsync { map -&gt;<br>                map.animateCamera(CameraUpdateFactory.newLatLng(latLng))<br>            }<br>        }<br>    )<br>}</pre><h3>Step 3: Migrate a Full Screen from XML + Fragment to Jetpack Compose</h3><p>Let’s take a real-world example — a user profile screen — and migrate it fully.</p><h3>Before: XML Layout + Fragment (the old way)</h3><p><strong>fragment_profile.xml</strong></p><pre>&lt;ScrollView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;&gt;<br><br>    &lt;LinearLayout<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:orientation=&quot;vertical&quot;<br>        android:padding=&quot;16dp&quot;&gt;<br><br>        &lt;ImageView<br>            android:id=&quot;@+id/ivAvatar&quot;<br>            android:layout_width=&quot;80dp&quot;<br>            android:layout_height=&quot;80dp&quot;<br>            android:layout_gravity=&quot;center_horizontal&quot; /&gt;<br><br>        &lt;TextView<br>            android:id=&quot;@+id/tvName&quot;<br>            android:layout_width=&quot;wrap_content&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:layout_gravity=&quot;center_horizontal&quot;<br>            android:textAppearance=&quot;?attr/textAppearanceHeadlineSmall&quot; /&gt;<br><br>        &lt;TextView<br>            android:id=&quot;@+id/tvEmail&quot;<br>            android:layout_width=&quot;wrap_content&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:layout_gravity=&quot;center_horizontal&quot;<br>            android:textAppearance=&quot;?attr/textAppearanceBodyMedium&quot; /&gt;<br><br>        &lt;Button<br>            android:id=&quot;@+id/btnEdit&quot;<br>            android:layout_width=&quot;match_parent&quot;<br>            android:layout_height=&quot;wrap_content&quot;<br>            android:text=&quot;Edit Profile&quot; /&gt;<br><br>    &lt;/LinearLayout&gt;<br>&lt;/ScrollView&gt;</pre><pre>class ProfileFragment : Fragment(R.layout.fragment_profile) {<br><br>    private val viewModel: ProfileViewModel by viewModels()<br>    private var _binding: FragmentProfileBinding? = null<br>    private val binding get() = _binding!!<br><br>    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {<br>        super.onViewCreated(view, savedInstanceState)<br>        _binding = FragmentProfileBinding.bind(view)<br><br>        viewLifecycleOwner.lifecycleScope.launch {<br>            viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {<br>                viewModel.uiState.collect { state -&gt;<br>                    binding.tvName.text = state.user?.name<br>                    binding.tvEmail.text = state.user?.email<br>                    Glide.with(this@ProfileFragment)<br>                        .load(state.user?.avatarUrl)<br>                        .circleCrop()<br>                        .into(binding.ivAvatar)<br>                    binding.btnEdit.setOnClickListener {<br>                        viewModel.onEditClicked()<br>                    }<br>                }<br>            }<br>        }<br>    }<br><br>    override fun onDestroyView() {<br>        super.onDestroyView()<br>        _binding = null<br>    }<br>}</pre><h3>After: Full Jetpack Compose Screen</h3><p>The ViewModel stays almost identical — this is the beauty of MVVM + StateFlow. Your business logic investment is fully protected.</p><p><strong>ProfileViewModel.kt</strong> (unchanged except minor cleanup)</p><pre>@HiltViewModel<br>class ProfileViewModel @Inject constructor(<br>    private val userRepository: UserRepository<br>) : ViewModel() {<br><br>    private val _uiState = MutableStateFlow(ProfileUiState())<br>    val uiState: StateFlow&lt;ProfileUiState&gt; = _uiState.asStateFlow()<br><br>    init {<br>        loadProfile()<br>    }<br><br>    private fun loadProfile() {<br>        viewModelScope.launch {<br>            userRepository.getProfile()<br>                .onSuccess { user -&gt; _uiState.update { it.copy(user = user) } }<br>                .onFailure { _uiState.update { it.copy(error = it.toString()) } }<br>        }<br>    }<br><br>    fun onEditClicked() { /* navigate */ }<br>}<br><br>data class ProfileUiState(<br>    val user: User? = null,<br>    val isLoading: Boolean = false,<br>    val error: String? = null<br>)</pre><p><strong>ProfileScreen.kt</strong> — replaces the Fragment and XML entirely:</p><pre>@Composable<br>fun ProfileScreen(<br>    viewModel: ProfileViewModel = hiltViewModel(),<br>    onEditClick: () -&gt; Unit<br>) {<br>    val uiState by viewModel.uiState.collectAsStateWithLifecycle()<br><br>    ProfileContent(<br>        uiState = uiState,<br>        onEditClick = onEditClick<br>    )<br>}<br><br>@Composable<br>private fun ProfileContent(<br>    uiState: ProfileUiState,<br>    onEditClick: () -&gt; Unit<br>) {<br>    Column(<br>        modifier = Modifier<br>            .fillMaxSize()<br>            .verticalScroll(rememberScrollState())<br>            .padding(16.dp),<br>        horizontalAlignment = Alignment.CenterHorizontally,<br>        verticalArrangement = Arrangement.spacedBy(8.dp)<br>    ) {<br>        AsyncImage(<br>            model = uiState.user?.avatarUrl,<br>            contentDescription = &quot;Avatar&quot;,<br>            modifier = Modifier<br>                .size(80.dp)<br>                .clip(CircleShape),<br>            contentScale = ContentScale.Crop<br>        )<br><br>        Text(<br>            text = uiState.user?.name.orEmpty(),<br>            style = MaterialTheme.typography.headlineSmall<br>        )<br><br>        Text(<br>            text = uiState.user?.email.orEmpty(),<br>            style = MaterialTheme.typography.bodyMedium,<br>            color = MaterialTheme.colorScheme.onSurfaceVariant<br>        )<br><br>        Button(<br>            onClick = onEditClick,<br>            modifier = Modifier.fillMaxWidth()<br>        ) {<br>            Text(&quot;Edit Profile&quot;)<br>        }<br>    }<br>}<br><br>// Free preview — no emulator needed<br>@Preview(showBackground = true)<br>@Composable<br>private fun ProfileContentPreview() {<br>    MaterialTheme {<br>        ProfileContent(<br>            uiState = ProfileUiState(<br>                user = User(name = &quot;Riya Shah&quot;, email = &quot;riya@example.com&quot;)<br>            ),<br>            onEditClick = {}<br>        )<br>    }<br>}</pre><p>What’s gone after migrating: no Fragment, no ViewBinding, no manual observer teardown, no Glide import, no onDestroyView. The UI is a pure function — same uiState in, same UI out, every time.</p><h3>Step 4: Replace RecyclerView with LazyColumn</h3><p>RecyclerView is usually the most painful XML migration. LazyColumn eliminates Adapter, ViewHolder, DiffUtil, and ItemDecoration entirely.</p><h3>Before: RecyclerView Adapter (120+ lines of boilerplate)</h3><pre>class ResidentAdapter(<br>    private val onItemClick: (Resident) -&gt; Unit<br>) : ListAdapter&lt;Resident, ResidentAdapter.ViewHolder&gt;(ResidentDiffCallback()) {<br><br>    class ViewHolder(private val binding: ItemResidentBinding) :<br>        RecyclerView.ViewHolder(binding.root) {<br><br>        fun bind(resident: Resident, onClick: (Resident) -&gt; Unit) {<br>            binding.tvName.text = resident.name<br>            binding.tvFlat.text = resident.flatNumber<br>            binding.root.setOnClickListener { onClick(resident) }<br>        }<br>    }<br><br>    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {<br>        return ViewHolder(<br>            ItemResidentBinding.inflate(<br>                LayoutInflater.from(parent.context), parent, false<br>            )<br>        )<br>    }<br><br>    override fun onBindViewHolder(holder: ViewHolder, position: Int) {<br>        holder.bind(getItem(position), onItemClick)<br>    }<br>}<br><br>class ResidentDiffCallback : DiffUtil.ItemCallback&lt;Resident&gt;() {<br>    override fun areItemsTheSame(old: Resident, new: Resident) = old.id == new.id<br>    override fun areContentsTheSame(old: Resident, new: Resident) = old == new<br>}</pre><h3>After: LazyColumn (25 lines, zero boilerplate)</h3><pre>@Composable<br>fun ResidentList(<br>    residents: List&lt;Resident&gt;,<br>    onResidentClick: (Resident) -&gt; Unit,<br>    modifier: Modifier = Modifier<br>) {<br>    LazyColumn(<br>        modifier = modifier,<br>        contentPadding = PaddingValues(vertical = 8.dp),<br>        verticalArrangement = Arrangement.spacedBy(4.dp)<br>    ) {<br>        items(<br>            items = residents,<br>            key = { it.id }  // replaces DiffUtil.areItemsTheSame<br>        ) { resident -&gt;<br>            ResidentItem(<br>                resident = resident,<br>                onClick = { onResidentClick(resident) }<br>            )<br>        }<br>    }<br>}<br><br>@Composable<br>private fun ResidentItem(<br>    resident: Resident,<br>    onClick: () -&gt; Unit,<br>    modifier: Modifier = Modifier<br>) {<br>    Card(<br>        onClick = onClick,<br>        modifier = modifier<br>            .fillMaxWidth()<br>            .padding(horizontal = 16.dp)<br>    ) {<br>        Row(<br>            modifier = Modifier.padding(16.dp),<br>            verticalAlignment = Alignment.CenterVertically,<br>            horizontalArrangement = Arrangement.spacedBy(12.dp)<br>        ) {<br>            Column {<br>                Text(text = resident.name, style = MaterialTheme.typography.bodyLarge)<br>                Text(<br>                    text = resident.flatNumber,<br>                    style = MaterialTheme.typography.bodySmall,<br>                    color = MaterialTheme.colorScheme.onSurfaceVariant<br>                )<br>            }<br>        }<br>    }<br>}</pre><p>No adapter. No ViewHolder. key = { it.id } handles diffing automatically — Compose tracks which items moved, appeared, or disappeared without a single extra class.</p><h3>Step 5: Migrate Navigation from nav_graph.xml to Navigation Compose</h3><p>If you’re using the Navigation Component, your nav_graph.xml with &lt;fragment&gt; destinations need to move to typed Compose destinations.</p><pre>// Define type-safe routes using sealed classes<br>sealed class Screen(val route: String) {<br>    object ResidentList : Screen(&quot;residents&quot;)<br>    object ResidentDetail : Screen(&quot;residents/{residentId}&quot;) {<br>        fun createRoute(residentId: String) = &quot;residents/$residentId&quot;<br>    }<br>    object Profile : Screen(&quot;profile&quot;)<br>}<br><br>// NavHost replaces your nav_graph.xml<br>@Composable<br>fun AppNavGraph(navController: NavHostController) {<br>    NavHost(<br>        navController = navController,<br>        startDestination = Screen.ResidentList.route<br>    ) {<br>        composable(Screen.ResidentList.route) {<br>            ResidentListScreen(<br>                onResidentClick = { residentId -&gt;<br>                    navController.navigate(Screen.ResidentDetail.createRoute(residentId))<br>                }<br>            )<br>        }<br><br>        composable(<br>            route = Screen.ResidentDetail.route,<br>            arguments = listOf(navArgument(&quot;residentId&quot;) { type = NavType.StringType })<br>        ) { backStackEntry -&gt;<br>            val residentId = backStackEntry.arguments?.getString(&quot;residentId&quot;) ?: return@composable<br>            ResidentDetailScreen(residentId = residentId)<br>        }<br><br>        composable(Screen.Profile.route) {<br>            ProfileScreen(onEditClick = { /* handle */ })<br>        }<br>    }<br>}</pre><blockquote><em>For new projects, use the type-safe Navigation 2.8+ API with </em><em>@Serializable route objects — it eliminates string-based route errors entirely.</em></blockquote><h3>5 Common Jetpack Compose Migration Mistakes to Avoid</h3><h4>1. Calling composables from non-Compose contexts</h4><p>Composables can only be called inside other composables or a setContent block. Trying to call them from a click listener or a ViewModel will fail at compile time.</p><h4>2. Forgetting remember for local state</h4><pre>// WRONG — resets on every recomposition<br>var count = 0<br><br>// CORRECT — survives recomposition<br>var count by remember { mutableStateOf(0) }</pre><h4>3. Missing key in LazyColumn</h4><p>Without key, Compose can&#39;t track item identity during list updates and re-renders the entire list—the equivalent of calling notifyDataSetChanged() on every update.</p><h4>4. Using collectAsState() instead of collectAsStateWithLifecycle()</h4><p>collectAsState() keeps collecting even when the app is in the background, wasting resources. Always use collectAsStateWithLifecycle() from lifecycle-runtime-compose to respect the Activity/Fragment lifecycle.</p><h4>5. Inline lambdas causing unnecessary recomposition</h4><pre>// WRONG — new lambda instance on every recomposition → forces child recomposition<br>Button(onClick = { viewModel.onSubmit() })<br><br>// CORRECT — stable lambda reference<br>val onSubmit = remember(viewModel) { { viewModel.onSubmit() } }<br>Button(onClick = onSubmit)</pre><h3>Jetpack Compose Migration Checklist (Save This)</h3><p>Use this as your screen-by-screen migration checklist:</p><ul><li>Add Compose BOM and dependencies to build.gradle.kts</li><li>Enable buildFeatures { compose = true }</li><li>Migrate ViewModel state from LiveData to StateFlow + UiState data class</li><li>Replace XML layout with a @Composable screen function</li><li>Replace RecyclerView + Adapter with LazyColumn + key parameter</li><li>Replace Glide/Picasso with AsyncImage (Coil)</li><li>Replace Fragment navigation with NavHost + composable destinations</li><li>Set ViewCompositionStrategy on any remaining ComposeView in Fragments</li><li>Add @Preview composables for each screen and component</li><li>Replace collectAsState() with collectAsStateWithLifecycle()</li><li>Delete the XML layout file and ViewBinding reference</li></ul><h3>Final Thoughts</h3><p>XML-to-Compose migration is not a sprint — it’s a feature-by-feature improvement. The interop layer (ComposeView, AndroidView) exists precisely to let you ship value to users while migrating underneath them.</p><p>Start with a leaf screen that has no deep navigation dependencies. Once you’ve done one screen end-to-end, the muscle memory kicks in and the rest accelerates. Your ViewModel and repository layers almost never change — all the complexity lives in the UI layer, and that’s exactly what Compose replaces cleanly.</p><p>The XML + View system will keep working. But after Google I/O 2026, writing XML for new screens isn’t just outdated—it&#39;s working against your own tooling. There has never been a clearer signal to migrate.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=333340fa0d3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jetpack Compose vs XML — The Real Answer for Android Teams in 2026]]></title>
            <link>https://medium.com/@krunalbhatt001/jetpack-compose-vs-xml-when-to-use-what-2026-7f622d881394?source=rss-e8422738ea83------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f622d881394</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Krunal Bhatt]]></dc:creator>
            <pubDate>Sun, 17 May 2026 20:55:01 GMT</pubDate>
            <atom:updated>2026-05-18T15:33:33.122Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*syXTROwmHLH5Xwg7An91kQ.png" /></figure><h3>The debate isn’t over. But the answer is clearer than ever.</h3><p>If you’ve been in Android development for more than a year, you’ve had this conversation. A new project lands on your desk, and someone asks, <em>“Are we going with Compose or XML?”</em></p><p>In 2026, Jetpack Compose is no longer the new kid on the block. It’s mature, production-ready, and Google’s officially recommended approach for building Android UIs. Yet XML layouts haven’t disappeared. Millions of apps still run on them, and legacy codebases aren’t going anywhere overnight.</p><p>So the real question isn’t <em>&quot;Which one is better?”</em> — it’s <strong>&quot;Which one is right for your situation?”</strong></p><p>I’ve built and migrated apps using both. Here’s my honest breakdown.</p><h3>🧱 Quick Overview</h3><p><strong>XML Layouts</strong> have been the backbone of Android UI since the beginning. You define your UI in .xml files and wire it up in your Activity or Fragment using ViewBinding or findViewById.</p><p><strong>Jetpack Compose</strong> is Android’s modern, declarative UI toolkit built entirely in Kotlin. Instead of describing <em>how</em> to change the UI, you describe <em>what</em> the UI should look like for a given state — and Compose handles the rest.</p><pre>// XML approach (imperative)<br>binding.tvUsername.text = &quot;Krunal&quot;<br>binding.btnLogin.isEnabled = true</pre><pre>// Compose approach (declarative)<br>Text(text = &quot;Krunal&quot;)<br>Button(enabled = true, onClick = { }) { Text(&quot;Login&quot;) }</pre><p>The difference in philosophy is immediately visible. And that difference has real consequences.</p><h3>✅ When to Use Jetpack Compose</h3><h3>1. Starting a New Project</h3><p>If you’re building from scratch in 2026, <strong>default to Compose</strong>. There’s no legacy to worry about, no migration cost, and you get all the modern benefits from day one.</p><h3>2. Your Team Knows Kotlin Well</h3><p>Compose is 100% Kotlin. If your team is already comfortable with Kotlin, Coroutines, and functional programming concepts, the learning curve is manageable. If not, budget time for it.</p><h3>3. You Want Faster UI Iteration</h3><p>Live previews in Android Studio, less boilerplate, and no back-and-forth between XML and Kotlin files means you ship UI faster. What used to take 3 files (XML layout + ViewHolder + Adapter) can now be a single composable function.</p><h3>4. Complex, Dynamic UIs</h3><p>Compose shines when UI state changes frequently. Animating between states, conditional rendering, and dynamic lists are all significantly cleaner in Compose than in XML.</p><pre>// Dynamic UI in Compose — clean and readable<br>@Composable<br>fun UserCard(isLoggedIn: Boolean) {<br>    if (isLoggedIn) {<br>        ProfileContent()<br>    } else {<br>        LoginPrompt()<br>    }<br>}</pre><h3>5. You Care About UI Consistency Across the App</h3><p>Composables are reusable by nature. Build a PrimaryButton once, use it everywhere, and no copy-pasting XML styles or hoping everyone remembered to apply the right theme attribute.</p><h3>6. Building a Design System</h3><p>If your app has a design system or follows Material Design 3, Compose integrates with it natively and gives you far more control over theming than XML ever did.</p><h3>🔧 When to Stick With XML</h3><h3>1. You Have a Large Legacy Codebase</h3><p>Migrating a 5-year-old app with hundreds of XML layouts to Compose overnight is not realistic. If it’s working and stable, a full rewrite isn’t justified. Migrate incrementally — screen by screen.</p><h3>2. Your Team Is Not Ready</h3><p>Compose has a learning curve. If your team is primarily Java/XML developers and the deadline is tight, forcing Compose can slow everything down. Skill up first, then migrate.</p><h3>3. You Need Certain Third-Party Library Support</h3><p>Most popular libraries (Glide, Maps, etc.) now have Compose wrappers, but some niche or older SDKs may still only support View-based integration. Always check before committing.</p><h3>4. You’re Working on a Simple, Stable Screen</h3><p>If a screen has existed for years, rarely changes, and works perfectly there’s no point migrating it. Don’t fix what isn’t broken.</p><h3>5. Performance-Critical Custom Views</h3><p>For very specific performance-heavy rendering (think custom chart views or game overlays), hand-crafted View subclasses with Canvas drawing still give you the most control. Compose has improved significantly here, but for extreme cases, custom Views remain the go-to.</p><h3>🤝 The Best of Both Worlds — Interoperability</h3><p>Here’s what most people miss: <strong>you don’t have to choose one or the other.</strong></p><p>Compose and XML play nicely together. You can embed a Composable inside an XML layout using ComposeView, or embed an existing View inside Compose using AndroidView.</p><pre>// Using an existing XML View inside Compose<br>AndroidView(<br>    factory = { context -&gt;<br>        MyLegacyCustomView(context)<br>    },<br>    update = { view -&gt;<br>        view.setData(myData)<br>    }<br>)</pre><p>This means you can migrate gradually, one screen, one component at a time, without a big-bang rewrite.</p><h3>📊 Side-by-Side Comparison</h3><p>Factor Jetpack Compose XML Layouts <strong>Language</strong> Kotlin only. XML + Kotlin/Java <strong>UI Paradigm:</strong> Declarative Imperative: Boilerplate, Low Medium to High <strong>Learning Curve: Medium,</strong> Low (familiar) <strong>Reusability:</strong> Excellent Moderate <strong>Animation</strong> Powerful &amp; simple Complex <strong>Tooling (2026)</strong> Excellent Excellent <strong>Performance</strong> Near-parity with Views Proven &amp; stable <strong>Legacy Support</strong> Via AndroidView Native <strong>Google’s Directions</strong> ✅ Recommended Maintenance mode</p><h3>🚦 My Rule of Thumb</h3><blockquote><strong><em>New project? Go Compose.</em></strong><em> </em><strong><em>Legacy project? Migrate incrementally.</em></strong><em> </em><strong><em>Tight deadline with XML-comfortable team? Finish in XML, plan the migration.</em></strong></blockquote><p>The goal isn’t to use the newest thing — it’s to ship quality software. Compose helps you do that faster and more maintainably in most modern scenarios. But pragmatism always wins over ideology.</p><h3>🔮 What’s Next?</h3><p>Compose is not slowing down. With <strong>Compose Multiplatform</strong> maturing, the same UI code you write for Android today may run on iOS, desktop, and web tomorrow. That’s a compelling reason to invest in it now.</p><p>XML layouts will be supported for years to come — Google isn’t pulling the rug. But new Jetpack features, tools, and improvements are increasingly Compose-first.</p><p>The direction is clear. The question is just <em>when</em> and for most teams in 2026, the answer is <em>now</em>.</p><h3>💬 Final Thoughts</h3><p>I’ve worked with both extensively, from delivering 20+ apps in XML to architecting multi-role platforms from scratch in Compose. The productivity gain with Compose is real, especially as projects grow in complexity.</p><p>If you haven’t started yet, start small. Pick one new screen, build it in Compose, and feel the difference. That one screen will convince you more than any article can.</p><p><em>Have questions or want to share your own migration experience? Drop a comment below — I’d love to hear how your team made the switch.</em></p><p><em>Follow me for more practical Android content — architecture, Jetpack deep dives, and real-world lessons from the field.</em></p><p><strong>Tags:</strong> Android Jetpack Compose Android Development Kotlin Mobile Development</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f622d881394" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>