<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: supriya shah</title>
    <description>The latest articles on DEV Community by supriya shah (@supriya_shah_1e9c3df6158c).</description>
    <link>https://dev.to/supriya_shah_1e9c3df6158c</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3697774%2Fb2737369-ff20-4f52-b0ce-e08756278312.png</url>
      <title>DEV Community: supriya shah</title>
      <link>https://dev.to/supriya_shah_1e9c3df6158c</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/supriya_shah_1e9c3df6158c"/>
    <language>en</language>
    <item>
      <title>I Was Using Sealed Classes Wrong in Android for Two Years. Here’s What Nobody Told Me.</title>
      <dc:creator>supriya shah</dc:creator>
      <pubDate>Fri, 27 Nov 2026 05:11:00 +0000</pubDate>
      <link>https://dev.to/supriya_shah_1e9c3df6158c/i-was-using-sealed-classes-wrong-in-android-for-two-years-heres-what-nobody-told-me-16b7</link>
      <guid>https://dev.to/supriya_shah_1e9c3df6158c/i-was-using-sealed-classes-wrong-in-android-for-two-years-heres-what-nobody-told-me-16b7</guid>
      <description>&lt;p&gt;Originally published on Medium:&lt;br&gt;
&lt;a href="https://medium.com/@supsabhi/i-was-using-sealed-classes-wrong-in-android-for-two-years-heres-what-nobody-told-me-3daa5cbdcbca?sharedUserId=supsabhi" rel="noopener noreferrer"&gt;https://medium.com/@supsabhi/i-was-using-sealed-classes-wrong-in-android-for-two-years-heres-what-nobody-told-me-3daa5cbdcbca?sharedUserId=supsabhi&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A beginner-friendly story about one of Kotlin’s most misunderstood features — and why the distinction finally matters.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We’ve all been there…Okay, real talk.&lt;/p&gt;

&lt;p&gt;When I first started Android development, while developing a sleek new feature to handle different states, I thought, “Okay, I’ll just use an Enum.” But then, reality hits. Success state needs to carry a User object, while Error state needs an Exception. Enums start sweating. They can’t do that.&lt;/p&gt;

&lt;p&gt;And then I came across the term &lt;code&gt;sealed class&lt;/code&gt; and thought, "Cool. It's like an enum, but fancier." I used it everywhere. State management? Sealed class. Network results? Sealed class. UI events? Sealed class.&lt;/p&gt;

&lt;p&gt;Then Kotlin 1.5 quietly introduced sealed interfaces and I thought, “Why would I ever need that? I already have sealed classes.”&lt;/p&gt;

&lt;p&gt;I was wrong. For two years.&lt;/p&gt;

&lt;p&gt;This article is the one I wish someone had handed me back then. Let’s fix this together — no jargon walls, no theory dumps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First, Let’s Talk About What “Sealed” Even Means&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think of sealed classes like a bouncer at an exclusive club 🚪&lt;/p&gt;

&lt;p&gt;The bouncer has a strict guest list. Only people on that list are allowed in — no walk-ins, no surprises. If your name isn’t on the list, you don’t get to be a subtype.&lt;/p&gt;

&lt;p&gt;That’s what &lt;strong&gt;sealed&lt;/strong&gt; means in Kotlin.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A sealed type restricts who can extend it. Only classes/objects defined in the &lt;strong&gt;same file (or package in newer Kotlin)&lt;/strong&gt; can be its subtypes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You define exactly who is allowed in (the subclasses) at compile time. This gives you something incredibly powerful: when you write a when expression on a sealed type, Kotlin knows every possible case. No surprises. No mystery subclasses coming from the outside world.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;sealed class&lt;/strong&gt; is a class that can hold state. It’s like a data container with a restricted family tree.&lt;/p&gt;

&lt;p&gt;Let’s look at a real Android use case: &lt;strong&gt;UI State management&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Imagine you’re building a screen that loads a list of movies. At any given moment, your screen is in one of these states:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MovieState&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="nc"&gt;Loading&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;MovieState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Success&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;movies&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Movie&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;MovieState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;MovieState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collectAsState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;MovieState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Loading&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;LoadingSpinner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;MovieState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Success&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;MovieList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;movies&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;movies&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;MovieState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Error&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;ErrorMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;// No `else` needed! Kotlin knows these are ALL the cases.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;code&gt;// No else needed&lt;/code&gt; comment? That's the magic. If you add a new state later and forget to handle it in when, the compiler yells at you. It's like having a very helpful, slightly annoying coworker who catches your mistakes before users do.&lt;/p&gt;

&lt;p&gt;Sealed classes are clean, readable, and safe. No nulls flying around, no magic strings, no mystery states.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But Here’s Where Sealed Classes Hit a Wall&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let me tell you about the day sealed classes broke my heart a little.&lt;/p&gt;

&lt;p&gt;I was building an app where I needed to represent user actions — things the user could do on a profile screen. Some actions were general (like Share), and some were specific (like Follow for social profiles, Buy for shop profiles).&lt;/p&gt;

&lt;p&gt;I thought: &lt;em&gt;“Easy! Sealed class it is.”&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProfileAction&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="nc"&gt;Share&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ProfileAction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="nc"&gt;Follow&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ProfileAction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;// Only for social profiles&lt;/span&gt;
    &lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="nc"&gt;Buy&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ProfileAction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;      &lt;span class="c1"&gt;// Only for shop profiles&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I wanted to add a second layer — maybe these actions also need to conform to an &lt;code&gt;Analyticsable&lt;/code&gt; interface (so I can track them), and an Undoable interface (so the user can undo them).&lt;/p&gt;

&lt;p&gt;And here’s where I hit the wall.&lt;/p&gt;

&lt;p&gt;A class can only extend ONE class. So if ProfileAction is a sealed class, none of my subtypes can extend anything else. They're stuck.&lt;/p&gt;

&lt;p&gt;This is not a Kotlin problem. This is just how inheritance works everywhere.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enter: Sealed Interfaces&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Kotlin 1.5 introduced sealed interfaces, and they solve exactly this problem.&lt;/p&gt;

&lt;p&gt;An interface doesn’t hold state by itself — it’s a contract, a set of promises. And crucially, a class can implement multiple interfaces.&lt;/p&gt;

&lt;p&gt;Sealed interfaces are the “cool younger sibling.” They do exactly what sealed classes do — restrict the hierarchy — but with one massive superpower: &lt;strong&gt;Multiple Inheritance.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let me rewrite the example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;ProfileAction&lt;/span&gt;
&lt;span class="c1"&gt;// Interfaces our actions can also conform to&lt;/span&gt;
&lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Analyticsable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;eventName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Undoable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;undo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now look at this beauty:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="nc"&gt;Share&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ProfileAction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Analyticsable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;eventName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"share_tapped"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="nc"&gt;Follow&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ProfileAction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Analyticsable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Undoable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;eventName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"follow_tapped"&lt;/span&gt;
    &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;undo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* unfollow logic */&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Buy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ProfileAction&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Analyticsable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;eventName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"buy_tapped"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each action can mix in only the behaviors it needs. &lt;code&gt;Share&lt;/code&gt; can be tracked. &lt;code&gt;Follow&lt;/code&gt; can be tracked AND undone. Buy holds data AND can be tracked.&lt;/p&gt;

&lt;p&gt;And when you use when:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;handleAction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ProfileAction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;Share&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;shareContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;Follow&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;followUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;Buy&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;openCheckout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Still exhaustive. Still safe. Way more flexible.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1nfcm18wr1zk131pfsgd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1nfcm18wr1zk131pfsgd.png" alt="sealed classes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So… When Do I Use Which?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let me be honest — for 80% of everyday Android use cases, sealed classes will serve you just fine. Don’t overthink it.&lt;/p&gt;

&lt;p&gt;Here’s my personal mental model:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reach for a Sealed Class when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You’re modeling UI states (Loading, Success, Error)&lt;/li&gt;
&lt;li&gt;You’re modeling network/repository results&lt;/li&gt;
&lt;li&gt;Your subtypes need constructor properties and you want everything in one tidy place&lt;/li&gt;
&lt;li&gt;You’re not combining behaviors from multiple type hierarchies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Reach for a Sealed Interface when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your subtypes need to implement other interfaces too&lt;/li&gt;
&lt;li&gt;You’re building a plugin-style or capability-based hierarchy&lt;/li&gt;
&lt;li&gt;You want a subtype that also extends another class&lt;/li&gt;
&lt;li&gt;You’re working on a multi-module project where different modules contribute subtypes (Kotlin 1.5+ allows this with interfaces across packages)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Golden Rule of Thumb 💡&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do I need to pass a variable to the parent? (e.g., sealed class Error(val code: Int)). If yes → use a Sealed Class.&lt;/li&gt;
&lt;li&gt;Does my subclass need to belong to multiple categories? If yes → use a Sealed Interface.&lt;/li&gt;
&lt;li&gt;Are you defining a simple state with no shared logic, but your subtypes need to mix in other behaviors? → use a Sealed Interface. It gives you the flexibility to grow.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Wrapping Up&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the modern Android world (especially with Jetpack Compose), you’ll find yourself reaching for sealed interfaces more often — for things like &lt;code&gt;NavigationEvents&lt;/code&gt; or &lt;code&gt;UiActions&lt;/code&gt; — because of their flexibility. However, for a robust ViewState that might need some base properties, the sealed class remains your best friend.&lt;/p&gt;

&lt;p&gt;You don’t need to refactor your entire codebase tonight. But next time you’re designing a hierarchy and think “I wish this subtype could also be X…” — remember sealed interfaces have your back.&lt;/p&gt;

&lt;p&gt;The compiler is your friend. Use sealed types, and let it do the heavy lifting of telling you when something’s missing or broken.&lt;/p&gt;

&lt;p&gt;That’s what Kotlin is all about.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If this helped you, drop a clap (or 50 — Medium lets you!) and share it within your team who’s been using sealed classes without questioning it. You might just save them two years. 🙂&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy coding. 🚀&lt;/em&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>mobile</category>
      <category>softwaredevelopment</category>
      <category>kotlin</category>
    </item>
    <item>
      <title>WebP: The Game-Changing Image Format Your Android App Has Been Waiting For</title>
      <dc:creator>supriya shah</dc:creator>
      <pubDate>Thu, 26 Nov 2026 05:04:00 +0000</pubDate>
      <link>https://dev.to/supriya_shah_1e9c3df6158c/webp-the-game-changing-image-format-your-android-app-has-been-waiting-for-1joh</link>
      <guid>https://dev.to/supriya_shah_1e9c3df6158c/webp-the-game-changing-image-format-your-android-app-has-been-waiting-for-1joh</guid>
      <description>&lt;p&gt;Originally published on Medium:&lt;br&gt;
&lt;a href="https://medium.com/@supsabhi/webp-the-game-changing-image-format-your-android-app-has-been-waiting-for-9c9f8fe21e86?sharedUserId=supsabhi" rel="noopener noreferrer"&gt;https://medium.com/@supsabhi/webp-the-game-changing-image-format-your-android-app-has-been-waiting-for-9c9f8fe21e86?sharedUserId=supsabhi&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’ve ever built an Android app, you’ve likely heard the advice: “Use SVGs to keep your app size down!” But as you know, while SVGs are great for icons, they can’t handle everything. You want high-quality visuals, but you also want a tiny APK size so users don’t abandon the download.&lt;/p&gt;

&lt;p&gt;What if I told you there’s a way to shrink your image sizes by 30% or more with zero code changes and almost zero effort?&lt;/p&gt;

&lt;p&gt;Switching to WebP is one of the lowest-effort, highest-impact optimizations you can make. While SVGs handle your vectors, WebP handles the heavy lifting for everything else. Here is why WebP is the secret weapon for a slimmer, faster Android app in 2026.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Exactly is WebP?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Developed by Google back in 2010 — yes, Google, the same company behind Android — WebP was designed specifically to make images smaller without making them look terrible. It is a modern image format that provides superior lossy and lossless compression for images on the web and in mobile apps.&lt;/p&gt;

&lt;p&gt;Think of it as the “best of both worlds.” It combines the top features of every format that came before it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;From JPEG: The ability to compress complex, high-detail photographs.&lt;/li&gt;
&lt;li&gt;From PNG: Full support for transparency (alpha channel).&lt;/li&gt;
&lt;li&gt;From GIF: Support for high-quality animations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The kicker? It does all this while staying 25% to 35% smaller than equivalent JPEGs or PNGs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Android Version Support for WebP: Is it Compatible?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A common worry for developers is backward compatibility. In 2026, this is no longer a concern. Android decodes WebP natively without the need for any external libraries:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API 14+ (Android 4.0+): Basic Lossy WebP support.&lt;/li&gt;
&lt;li&gt;API 18+ (Android 4.3+): Full support for Lossless and Transparent WebP.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your minSdkVersion is 18 or above (which is standard for almost every modern app), you have full, native support with zero extra dependencies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WebP vs. SVG: Which One Should You Use?&lt;/strong&gt;&lt;br&gt;
It’s easy to get confused. If both reduce app size, which one do you pick? The answer depends entirely on the content of the image.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SVGs&lt;/strong&gt; (converted to VectorDrawable in Android) are best for icons, logos, and simple illustrations. They use mathematical paths, meaning they are infinitely scalable and never get blurry. However, they are not meant for photos or gradient-heavy art.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WebP&lt;/strong&gt; is a raster format, meaning it works on a grid of pixels. This makes it the perfect choice for complex graphics, screenshots, and hero images. While it has limited scalability (it will pixelate if over-stretched), it is much smaller than PNG or JPEG.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&amp;gt; The Golden Rule: If it’s a simple shape or icon, use SVG. If it’s a photo of a sunset or a complex character illustration, use WebP.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Use WebP in Your Android App?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Drastic APK Size Reduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every kilobyte counts toward your “install-complete” rate. WebP uses advanced compression algorithms to shrink a 1MB PNG down to roughly 100KB without a visible loss in quality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Better Performance and Reduced I/O Bottlenecks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A common misconception is that WebP saves RAM. In reality, a decoded bitmap takes up the same memory space regardless of the source format. However, WebP shines during the loading phase. Smaller files on disk mean faster reading (I/O). This reduces pressure on the Main Thread, making your RecyclerView scrolls smoother and your UI feel more responsive—especially on budget devices.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Full Transparency &amp;amp; Animation Support&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You no longer need heavy PNGs for transparent “stickers” or UI overlays. WebP handles transparency with much higher efficiency. It also serves as a great alternative to GIFs, offering a wider color range at a fraction of the file size.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Convert Images to WebP in Android Studio&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You don’t need third-party tools or designer exports. Android Studio has a built-in conversion engine:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Locate your file: Navigate to res/drawable and right-click your PNG or JPEG.&lt;/li&gt;
&lt;li&gt;Select “Convert to WebP”: This is available directly in the context menu.&lt;/li&gt;
&lt;li&gt;Choose Encoding: A dialog will let you choose between Lossy and Lossless. You can adjust the quality slider; 80–90% is usually indistinguishable from the original but offers massive savings.&lt;/li&gt;
&lt;li&gt;Finish: Android Studio replaces the file and automatically updates your references.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Implementation: Loading WebP in Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The best part? You don’t have to change a single line of code. Standard Android components and popular image-loading libraries (like Coil, Glide, or Picasso) handle WebP transparently.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Works exactly the same as a PNG&lt;/span&gt;
&lt;span class="nc"&gt;Glide&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;drawable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hero_banner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// hero_banner.webp&lt;/span&gt;
     &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;into&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;imageView&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Final Verdict: Is it Worth It?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As developers, we often focus on architecture and clean code, but we shouldn’t ignore the “weight” of our assets. Switching from PNG to WebP is a high-reward, low-effort move.&lt;/p&gt;

&lt;p&gt;It makes your app faster to download, quicker to load, and more respectful of your user’s storage. In the competitive world of the Play Store, a slim app is a winning app. If you still have PNGs sitting in your folders that aren’t icons, today is a good day to right-click and convert.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy coding!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>imageformat</category>
      <category>mobile</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Rich Continuous Notifications in Android 16</title>
      <dc:creator>supriya shah</dc:creator>
      <pubDate>Wed, 25 Nov 2026 05:07:00 +0000</pubDate>
      <link>https://dev.to/supriya_shah_1e9c3df6158c/rich-continuous-notifications-in-android-16-556m</link>
      <guid>https://dev.to/supriya_shah_1e9c3df6158c/rich-continuous-notifications-in-android-16-556m</guid>
      <description>&lt;p&gt;Originally published on Medium:&lt;br&gt;
&lt;a href="https://medium.com/@supsabhi/rich-continuous-notifications-in-android-16-eba920fa9d19?sharedUserId=supsabhi" rel="noopener noreferrer"&gt;https://medium.com/@supsabhi/rich-continuous-notifications-in-android-16-eba920fa9d19?sharedUserId=supsabhi&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notifications are one of the most visible parts of an Android app — yet for years, they’ve mostly been static. A message arrives, the user reads it, and that’s it.&lt;/p&gt;

&lt;p&gt;Remember the days of constantly unlocking your phone, swiping down, and tapping into an app just to see if your Uber was almost here, or if your food order had left the restaurant? Yeah, me too. It was a little bit of a digital dance, wasn’t it?&lt;/p&gt;

&lt;p&gt;But modern apps don’t work that way anymore.&lt;/p&gt;

&lt;p&gt;Well, with Android 16, those days are officially a thing of the past. Food deliveries move. Downloads progress. Navigation updates every second. Music keeps playing.&lt;/p&gt;

&lt;p&gt;Android 16 introduces Rich Continuous Notifications to handle exactly these ongoing experiences — cleanly and intelligently.&lt;/p&gt;

&lt;p&gt;Android 16 is bringing a new way for apps to stay visible and helpful without being annoying: Rich Continuous Notifications (often called Rich Ongoing Notifications), or as I like to call them, “Live Updates for Everything Important.” These notifications can appear in the status bar as compact indicators and expand on the lock screen, showing live text, color accents, and quick actions — conceptually similar to Apple’s Dynamic Island.&lt;/p&gt;

&lt;p&gt;This isn’t just another small tweak; it’s a fundamental shift in how your phone keeps you informed about active events. Let’s dive in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are Rich Continuous Notifications?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine your phone’s notification shade, but instead of static messages, you have dynamic, real-time “widgets” that live right there, updating constantly. That’s the essence of Rich Continuous Notifications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rich Continuous Notifications&lt;/strong&gt; are notifications that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stay visible while a task is ongoing&lt;/li&gt;
&lt;li&gt;Update their content in real time&lt;/li&gt;
&lt;li&gt;Avoid creating multiple notification entries&lt;/li&gt;
&lt;li&gt;Clearly communicate “something is happening right now”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Android 16 is also pushing live updates and smarter notification organization, so users see fewer noisy alerts and more useful, ongoing information at a glance.&lt;/p&gt;

&lt;p&gt;The big deal? You get crucial, up-to-the-second information without disrupting what you’re doing. It’s less friction, less frustration, and frankly, a much more human way for your phone to communicate with you.&lt;/p&gt;

&lt;p&gt;Before Android 16, a &lt;strong&gt;“live”&lt;/strong&gt; notification might have meant a rapid-fire series of new notifications: “Your driver is 5 mins away!”, then “Your driver is 3 mins away!” This cluttered your notification history and often felt intrusive.&lt;/p&gt;

&lt;p&gt;Now? It’s &lt;strong&gt;one single, smart notification&lt;/strong&gt; that gracefully updates its content. It often starts as a compact indicator in your status bar, expands on your lock screen, and can even offer quick actions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Android 16 focuses on this&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before Android 16:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Developers misused foreground services&lt;/li&gt;
&lt;li&gt;Apps showed long-running notifications for background work&lt;/li&gt;
&lt;li&gt;Users lost trust and disabled notifications&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Android 16 pushes a clear message:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Only show continuous notifications when the user genuinely benefits from live visibility.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This leads to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Less notification clutter&lt;/li&gt;
&lt;li&gt;More transparency&lt;/li&gt;
&lt;li&gt;Better battery and system performance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A good rule: if you could justify a persistent notification with real-time updates today, it is probably a candidate for a Rich Continuous Notification in Android 16.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When should you use them?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You should use Rich Continuous Notifications when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There is an activity with a clear start and end, like a ride, a download, or a workout&lt;/li&gt;
&lt;li&gt;The user benefits from seeing live status without opening the app&lt;/li&gt;
&lt;li&gt;The information changes over time (progress, ETA, countdown, score, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Avoid using them for:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One-off alerts (like “New message”)&lt;/li&gt;
&lt;li&gt;Purely promotional or marketing notifications&lt;/li&gt;
&lt;li&gt;Static information that rarely changes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Setup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Create a notification channel&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;NotificationChannel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="no"&gt;CHANNEL_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"Live Updates"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;NotificationManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;IMPORTANCE_LOW&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;notificationManager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createNotificationChannel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;IMPORTANCE_LOW is usually ideal — visible, but &lt;strong&gt;not noisy.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Request notification permission&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Android 13+ requires runtime permission for posting notifications:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;uses-permission&lt;/span&gt;
    &lt;span class="na"&gt;android:name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"android.permission.POST_NOTIFICATIONS"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rich Continuous Notifications in Android 16 build &lt;strong&gt;on top of ongoing foreground notifications&lt;/strong&gt;. While Android 16 improves how ongoing notifications are displayed and prioritized by the system, there is currently no separate public permission specifically for “promoted” notifications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Build an ongoing live-update notification&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;
&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;notification&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;NotificationCompat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Builder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"live_updates"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setContentTitle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Ride to Dubai Mall"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setContentText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Arriving in 5 minutes"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setSmallIcon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;drawable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ic_ride&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setOngoing&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setCategory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Notification&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;CATEGORY_TRANSPORT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;setOngoing(true) makes it persistent&lt;/li&gt;
&lt;li&gt;Using a meaningful category (like CATEGORY_TRANSPORT) helps the system treat it correctly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note: Android 16 may visually elevate certain ongoing notifications automatically based on system heuristics. Apps request this behavior implicitly by using foreground services correctly, not via a dedicated API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Start the foreground service&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;startForeground(NOTIFICATION_ID, notification)&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This tells Android:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“This task matters to the user. Keep it alive and visible.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;5. Update the notification as the state changes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The key to making a notification feel “continuous” is to update it over time instead of sending new notifications. Always reuse the same notification ID.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No duplicates. No spam.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For example, updating ETA as the car moves:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;updateRideEta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;notificationId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;minutes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;manager&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;NotificationManagerCompat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;NotificationCompat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Builder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"live_updates"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setSmallIcon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;drawable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ic_ride&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setContentTitle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Ride to Dubai Mall"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setContentText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Arriving in $minutes minutes"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setOngoing&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setCategory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Notification&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;CATEGORY_TRANSPORT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;manager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;notificationId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each call with the same &lt;code&gt;notificationId&lt;/code&gt; replaces the previous one, keeping a single live notification instead of spamming the user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6.Ending the task&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the trip ends:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;endRide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;stopForeground&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;STOP_FOREGROUND_REMOVE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;stopSelf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This removes the notification automatically and tells the system the task is complete.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What makes Android 16 “rich”?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Android 16 emphasizes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clear task purpose&lt;/li&gt;
&lt;li&gt;Meaningful user-facing updates&lt;/li&gt;
&lt;li&gt;Short-lived, task-focused foreground services&lt;/li&gt;
&lt;li&gt;Better system prioritization and controls&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s no longer just “keep a notification running” — it’s about responsible live updates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rich Continuous Notifications in Android 16 aren’t about adding complexity — they’re about clarity. They represent a significant leap forward in Android’s user experience.&lt;/p&gt;

&lt;p&gt;This is a chance to bring your app’s most important live information into the status bar in a compact, respectful, and genuinely useful way — one that users actually appreciate.&lt;/p&gt;

&lt;p&gt;If you’re building modern Android apps, mastering this pattern will significantly improve user trust and experience.&lt;/p&gt;

&lt;p&gt;Say the word 🚀&lt;/p&gt;

</description>
      <category>android</category>
      <category>androiddev</category>
      <category>mobile</category>
      <category>development</category>
    </item>
    <item>
      <title>Remote Compose: The Future of Dynamic Android UIs (And How It Compares to SDUI)</title>
      <dc:creator>supriya shah</dc:creator>
      <pubDate>Tue, 24 Nov 2026 05:12:00 +0000</pubDate>
      <link>https://dev.to/supriya_shah_1e9c3df6158c/remote-compose-the-future-of-dynamic-android-uis-and-how-it-compares-to-sdui-bhg</link>
      <guid>https://dev.to/supriya_shah_1e9c3df6158c/remote-compose-the-future-of-dynamic-android-uis-and-how-it-compares-to-sdui-bhg</guid>
      <description>&lt;p&gt;Originally published on Medium:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@supsabhi/remote-compose-the-future-of-dynamic-android-uis-and-how-it-compares-to-sdui-444a9430de13?sharedUserId=supsabhi" rel="noopener noreferrer"&gt;https://medium.com/@supsabhi/remote-compose-the-future-of-dynamic-android-uis-and-how-it-compares-to-sdui-444a9430de13?sharedUserId=supsabhi&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine you run a shopping app. Black Friday is tomorrow. Your design team wants a giant banner on the home screen. Normally, that means a code change, a PR, a review, a build, a Play Store submission, and then… waiting 2–3 days for approval.&lt;/p&gt;

&lt;p&gt;What if you could just push that banner from your server — instantly, to all users — without touching the app code at all?&lt;/p&gt;

&lt;p&gt;That’s exactly the problem Remote Compose (and its older cousin, SDUI) are built to solve.&lt;/p&gt;

&lt;p&gt;First, Let’s Understand the Problem&lt;br&gt;
In a traditional Android app, your UI is baked into the APK. You ship it, users install it, and it stays that way until the next update. This is fine for stable features, but terrible for:&lt;/p&gt;

&lt;p&gt;A/B testing — want to test two versions of a checkout button? That’s a whole release cycle.&lt;br&gt;
Dynamic promotions — flash sales, seasonal banners, real-time feature flags.&lt;br&gt;
Fixing a broken layout — you spotted a UI bug in production. Users are stuck with it for days.&lt;br&gt;
The dream is a UI that your backend can control in real time. That’s where server-driven UI comes in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Server-Driven UI (SDUI)?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SDUI&lt;/strong&gt; is an architectural pattern where the server tells the app what to render, rather than the app deciding on its own.&lt;/p&gt;

&lt;p&gt;Instead of your Android code hardcoding if (isPromoWeek) showBanner(), the server sends down a JSON payload that says: "render a banner component with this title, this color, and this action."&lt;/p&gt;

&lt;p&gt;The app becomes a dumb renderer. It just reads the JSON and draws what it’s told.&lt;/p&gt;

&lt;p&gt;A Simple SDUI Example&lt;/p&gt;

&lt;p&gt;Server sends this JSON:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"banner"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"50% Off Today Only!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"backgroundColor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"#FF5722"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"navigate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"screen"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"deals"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your Android app parses this and renders a banner. The server changes the JSON tomorrow — the banner disappears. No app update.&lt;/p&gt;

&lt;p&gt;The Classic SDUI Code Pattern (XML/View era)&lt;br&gt;
// Old-school SDUI with Views&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;renderComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ComponentModel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ViewGroup&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"banner"&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;banner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BannerView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;banner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setTitle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;banner&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setBackgroundColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Color&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parseColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;banner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="s2"&gt;"button"&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;btn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;btn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;
            &lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;btn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works, but &lt;strong&gt;it’s verbose, error-prone, and managing state across dynamic Views is painful&lt;/strong&gt;. Every new component type needs a new when branch, manual view inflation, and careful lifecycle management.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enter Remote Compose&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Remote Compose is SDUI — but reimagined for the Jetpack Compose era.&lt;/p&gt;

&lt;p&gt;Instead of inflating Views from JSON, your server sends a Compose-compatible UI description, and the client renders it using Compose’s declarative system. It’s cleaner, more expressive, and far easier to maintain.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Think of it this way: SDUI was the answer to “how do we make dynamic UIs?” Remote Compose is the answer to “how do we make dynamic UIs well, in 2024+?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Remote Compose vs SDUI: The Core Difference&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Both solve the same problem, but they’re built for different eras of Android development.&lt;/p&gt;

&lt;p&gt;Classic SDUI runs on the old View system — you inflate XML layouts, wire up TextViews and Buttons manually, and manage state yourself. It gets the job done, but the boilerplate piles up fast. Remote Compose swaps all of that for Jetpack Compose’s declarative model, so the rendering is cleaner and state is handled naturally by the runtime.&lt;/p&gt;

&lt;p&gt;The payload is different too. SDUI typically sends plain JSON that your app parses into component types. Remote Compose sends a structured UI tree — closer to actual Compose nodes — which the client renders directly without a component-by-component when switch.&lt;/p&gt;

&lt;p&gt;Animations and theming are where the gap really shows. In classic SDUI, adding smooth transitions across dynamically rendered Views is genuinely painful. In Remote Compose, animations are just… Compose animations. They work the same way they always do.&lt;/p&gt;

&lt;p&gt;The tradeoff is maturity. SDUI has been battle-tested at companies like Airbnb and Twitter for years. Remote Compose is newer and still evolving — great for greenfield projects, but you’ll occasionally hit rough edges in tooling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Remote Compose Actually Works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Remote Compose works in three steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Server serializes a Compose UI tree&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of a full Compose function running on the server, the server produces a description of what the UI should look like — a tree of UI nodes (text, image, button, column, row, etc.) encoded as a compact binary or JSON payload.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Client receives and deserializes the tree&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The app receives this payload, parses it into a local representation of Compose nodes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Client renders using Compose&lt;/strong&gt;&lt;br&gt;
The local Compose runtime renders those nodes just like normal Compose composables — with full support for recomposition, state, and animations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s Code — Setting Up&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;// Dependency in build.gradle&lt;br&gt;
&lt;code&gt;implementation("androidx.remotecallback:remotecallback:1.0.0-alpha02")&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;// (Remote Compose is still evolving — check the latest alpha)&lt;/p&gt;

&lt;p&gt;Server Side&lt;/p&gt;

&lt;p&gt;The server produces a UI tree — here’s a conceptual example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;
&lt;span class="c1"&gt;// Server generates this UI description&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;buildPromoUI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;RemoteViews&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;remoteColumn&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;remoteText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Flash Sale — 3 Hours Only!"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;fontSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Color&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;White&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;fontWeight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;FontWeight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Bold&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;remoteSpacer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;remoteButton&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;label&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Shop Now"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;NavigateAction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;screen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"deals"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;backgroundColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Color&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mh"&gt;0xFFFF5722&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Client Side&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Composable&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nc"&gt;DynamicScreen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;DynamicViewModel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;uiState&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt; &lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remoteUI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collectAsState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uiState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;Loading&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;CircularProgressIndicator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;Success&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;RemoteComposeRenderer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;uiState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// The server payload&lt;/span&gt;
            &lt;span class="n"&gt;modifier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Modifier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fillMaxSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Couldn't load content"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The RemoteComposeRenderer is the magic piece — it takes the server payload and renders it as real Compose UI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Real-World Comparison: Home Screen Feature&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s build the same “promotional banner” feature in both approaches.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SDUI Approach (Classic)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Server JSON:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"screen"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"home"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"components"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"promo_banner"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Weekend Deal"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"subtitle"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Up to 40% off"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"image_url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://cdn.example.com/promo.png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"cta_text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"View Deals"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"cta_action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"OPEN_DEALS_PAGE"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Android Client (View-based SDUI):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ComponentModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;subtitle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;imageUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;ctaText&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;ctaAction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;renderSDUI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ComponentModel&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;LinearLayout&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"promo_banner"&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;view&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;layoutInflater&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;inflate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;layout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;promo_banner&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;findViewById&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;TextView&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;
            &lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;findViewById&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;TextView&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subtitle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subtitle&lt;/span&gt;
            &lt;span class="nc"&gt;Glide&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imageUrl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;into&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findViewById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;findViewById&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cta&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;apply&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ctaText&lt;/span&gt;
                &lt;span class="n"&gt;setOnClickListener&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;handleAction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ctaAction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works. But notice — every new component needs a new XML layout file, new when branch, and manual view wiring. Adding 10 component types means 10 layout files and 10 code paths.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remote Compose Approach&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Server produces a Compose tree (conceptual):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nf"&gt;remoteColumn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;modifier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RemoteModifier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;remoteImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://cdn.example.com/promo.png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;contentScale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ContentScale&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Crop&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;modifier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RemoteModifier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fillMaxWidth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;height&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;remoteSpacer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;remoteText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Weekend Deal"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RemoteTextStyle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headlineMedium&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;remoteText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Up to 40% off"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RemoteTextStyle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bodyMedium&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Color&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Gray&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;remoteSpacer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;remoteButton&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"View Deals"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;onClick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RemoteAction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"deals_screen"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Client just renders it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Composable&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nc"&gt;HomeScreen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;uiTree&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt; &lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;homeTree&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collectAsState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nc"&gt;RemoteComposePlayer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;modifier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Modifier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fillMaxSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;uiTree&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it. The client has zero knowledge of what “promo banner” means. It just renders whatever the server describes. Add a new section tomorrow — &lt;strong&gt;zero client code changes&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When to Use What&lt;br&gt;
Stick with Classic SDUI if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your codebase is still View-based (XML layouts)&lt;/li&gt;
&lt;li&gt;You need mature tooling and a well-documented pattern&lt;/li&gt;
&lt;li&gt;Your team isn’t fully on Compose yet&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use Remote Compose if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You’re building greenfield in Compose&lt;/li&gt;
&lt;li&gt;You want animations, state, and theming to be part of the server-driven experience&lt;/li&gt;
&lt;li&gt;You want to eliminate the rendering boilerplate that SDUI demands&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use neither if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your UI rarely changes (SDUI adds complexity — don’t pay for what you don’t need)&lt;/li&gt;
&lt;li&gt;Your team is small and the release cycle is fast enough&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Gotchas Nobody Talks About&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt;. Your server controls what renders on screen. A compromised backend could push malicious UI. Always validate payloads server-side and sanitize actions on the client.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Versioning&lt;/strong&gt;. If your server sends a component your old app client doesn’t know how to render — what happens? You need a fallback strategy (skip unknown nodes, show placeholder, etc.).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Accessibility&lt;/strong&gt;. Server-driven UIs can break screen reader semantics if you’re not careful. Make sure your component contracts include accessibility labels.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Debugging&lt;/strong&gt;. “Why is my UI wrong?” becomes a multi-layer question — is it the server payload, the deserializer, or the renderer? Good logging at each layer is non-negotiable.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Wrapping Up&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Remote Compose isn’t magic, and it’s not for every app. But if you’ve ever felt the pain of waiting 3 days for a Play Store review just to change a button color — this architecture is worth understanding deeply.&lt;/p&gt;

&lt;p&gt;Start with SDUI if you’re new to server-driven patterns. It’ll teach you the fundamentals. Then, as your team adopts Compose, Remote Compose becomes the natural evolution.&lt;/p&gt;

&lt;p&gt;The future of dynamic Android UIs is one where the server and client are true partners — the server owns what to show, and the client owns how to show it beautifully.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Happy composing.&lt;/em&gt; 🚀&lt;/p&gt;

</description>
      <category>android</category>
      <category>mobile</category>
      <category>remote</category>
      <category>serverdrivenui</category>
    </item>
    <item>
      <title>Kotlin Scope Functions Finally Explained (Without the Confusion)</title>
      <dc:creator>supriya shah</dc:creator>
      <pubDate>Mon, 23 Nov 2026 05:15:00 +0000</pubDate>
      <link>https://dev.to/supriya_shah_1e9c3df6158c/kotlin-scope-functions-finally-explained-without-the-confusion-p38</link>
      <guid>https://dev.to/supriya_shah_1e9c3df6158c/kotlin-scope-functions-finally-explained-without-the-confusion-p38</guid>
      <description>&lt;p&gt;Originally published on Medium:&lt;br&gt;
&lt;a href="https://medium.com/@supsabhi/kotlin-scope-functions-finally-explained-without-the-confusion-0cb943d6ced2?sharedUserId=supsabhi" rel="noopener noreferrer"&gt;https://medium.com/@supsabhi/kotlin-scope-functions-finally-explained-without-the-confusion-0cb943d6ced2?sharedUserId=supsabhi&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Master these once, and suddenly every Kotlin codebase starts making a lot more sense.&lt;/p&gt;

&lt;p&gt;If you’ve been learning Kotlin, chances are you’ve come across scope functions and thought:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Why are there FIVE of them… and why do they all look the same?” 😅&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When I first encountered Kotlin’s scope functions, my reaction was something similar.So don’t worry, you’re not alone.Scope functions are one of those Kotlin features that looks confusing on the surface but becomes genuinely delightful once it clicks. This article is that click..!&lt;/p&gt;

&lt;p&gt;In this article, I’ll break down **SCOPE FUNCTIONS **in the simplest way possible — no jargon, just intuition and examples.By the end, you’ll know exactly what each one does, when to reach for it, and — just as importantly — when not to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, what even is a scope function?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A scope function is a function that executes a block of code within the context of an object. That’s the official definition, and it’s honestly not very helpful on its own.Let me try again.&lt;/p&gt;

&lt;p&gt;Imagine you’re setting up a new User object. Without scope functions, you’d do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Alice"&lt;/span&gt;
&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;
&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"alice@example.com"&lt;/span&gt;
&lt;span class="nf"&gt;saveUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That works fine. But notice how you keep writing user. over and over?&lt;/p&gt;

&lt;p&gt;Scope functions let you “enter” the object for a moment, do everything you need, and step back out — without repeating yourself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;apply&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Alice"&lt;/span&gt;
&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;
&lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"alice@example.com"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;saveUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cleaner, right? That’s the essence of it.&lt;/p&gt;

&lt;p&gt;Basically all scope functions do the same thing:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;👉 They run a block of code using an object&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The real differences are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How they refer to the object (this vs it)&lt;/li&gt;
&lt;li&gt;What they return (object vs result)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;🔍 Let’s Understand Them One by One&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.let — Safe Calls &amp;amp; Transformations. — Use it · Returns the lambda result&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;let takes the object as it inside the block, and returns whatever the last expression in the block evaluates to.&lt;/p&gt;

&lt;p&gt;Use let when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want to work with a nullable object&lt;/li&gt;
&lt;li&gt;You want to transform data
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;
&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;cityName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Dubai"&lt;/span&gt;
&lt;span class="n"&gt;cityName&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;let&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello $it"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="s1"&gt;' is the non-null name
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Here, it represents the object (name)&lt;/p&gt;

&lt;p&gt;💡 Common use case:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Avoid null checks&lt;/li&gt;
&lt;li&gt;Perform small transformations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2.run — Initialize + Compute Result — Use this · Returns the lambda result&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;run is like let, but instead of it, the object becomes this inside the block — so you can access its members directly without a prefix.&lt;/p&gt;

&lt;p&gt;Use run when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want to execute multiple operations&lt;/li&gt;
&lt;li&gt;You want to return a result
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// 'this' is the user object&lt;/span&gt;
&lt;span class="s2"&gt;"${name} is ${age} years old"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. with — Operate on an Object (Non-extension)-Use this · Returns the lambda result · Not an extension&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;with is the odd one out — you pass the object as an argument rather than calling it on the object. Everything else is similar to run.&lt;/p&gt;

&lt;p&gt;Use with when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You already have an object&lt;/li&gt;
&lt;li&gt;You want cleaner code
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"John"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Cleaner than repeating person.name, person.age&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. apply — Object Configuration — Use this · Returns the object itself&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the builder’s best friend. apply gives you this inside the block, and when you’re done, it returns the original object — not the result of the block.&lt;/p&gt;

&lt;p&gt;Use apply when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want to configure an object&lt;/li&gt;
&lt;li&gt;You want the same object back&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;val person = Person().apply { name = "John" age = 25 }&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
This is perfect for configuring an object right after creating it. The classic use case for object initialization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.also — Side Effects (Logging, Debugging) — Use it · Returns the object itself&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;also is like apply, but uses it instead of this. It’s great when you want to do something extra with the object — like log it — without interrupting the main flow.&lt;/p&gt;

&lt;p&gt;Use also when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want to do something extra (like logging)&lt;/li&gt;
&lt;li&gt;Without modifying the object
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;also&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Value is $it"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;👉 It returns the original object unchanged&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simple Trick to Remember&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of memorizing everything, just remember this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Need result? → let, run, with&lt;/li&gt;
&lt;li&gt;Need object back? → apply, also&lt;/li&gt;
&lt;li&gt;Using it? → let, also&lt;/li&gt;
&lt;li&gt;Using this? → run, with, apply&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;A real-world example that uses all five&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here’s a contrived-but-illustrative snippet that shows them all working together. Don’t use all five in one chain like this in real code — but it’s a great way to see the differences side by side.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nf"&gt;fetchUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;let&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;rawUser&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;// null-check, rename to rawUser&lt;/span&gt;
&lt;span class="nf"&gt;validateUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rawUser&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// returns a validated User&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;apply&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// configure the validated user&lt;/span&gt;
&lt;span class="n"&gt;role&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"admin"&lt;/span&gt;
&lt;span class="n"&gt;verified&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;also&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// side effect: log it&lt;/span&gt;
&lt;span class="nb"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Saving: ${it.name}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// compute a result&lt;/span&gt;
&lt;span class="nf"&gt;saveUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// returns the save result&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why So Many Scope Functions?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Because each one solves a slightly different problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cleaner null handling → let&lt;/li&gt;
&lt;li&gt;Computation → run&lt;/li&gt;
&lt;li&gt;Object setup → apply&lt;/li&gt;
&lt;li&gt;Side effects → also&lt;/li&gt;
&lt;li&gt;Readability → with&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Common beginner mistakes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using apply when you need a result. If you find yourself ending an apply block with a value you want to capture, switch to run. apply always gives you back the object, ignoring your last expression.&lt;/p&gt;

&lt;p&gt;Chaining scope functions for no reason. Scope functions make code more readable — but only when used purposefully. If a plain if statement is clearer, use it. Readability wins.&lt;/p&gt;

&lt;p&gt;Forgetting that with isn’t null-safe. You can’t do nullableObj?.with { … } because with isn’t an extension function. Reach for let or run when null safety is involved.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Scope functions are one of those things you pick up gradually. At first, scope functions feel like overkill. But once you start using them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your code becomes cleaner&lt;/li&gt;
&lt;li&gt;You reduce repetition&lt;/li&gt;
&lt;li&gt;You write more expressive Kotlin&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Don’t try to memorize them — instead, start using just let and apply, which cover 80% of cases. The others will start feeling natural as you read more Kotlin code.&lt;br&gt;
The next time you see &lt;strong&gt;let, run, or apply&lt;/strong&gt;… don’t panic — you’re just one scope away from cleaner Kotlin 😄.. Happy Scoping..!!&lt;/p&gt;

&lt;p&gt;Happy Coding ! 🚀 😄&lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>android</category>
      <category>mobile</category>
      <category>kotlin</category>
    </item>
    <item>
      <title>Mastering Pagination in Jetpack Compose: Paging 3 vs snapshotFlow</title>
      <dc:creator>supriya shah</dc:creator>
      <pubDate>Fri, 20 Nov 2026 05:20:00 +0000</pubDate>
      <link>https://dev.to/supriya_shah_1e9c3df6158c/mastering-pagination-in-jetpack-compose-paging-3-vs-snapshotflow-51oa</link>
      <guid>https://dev.to/supriya_shah_1e9c3df6158c/mastering-pagination-in-jetpack-compose-paging-3-vs-snapshotflow-51oa</guid>
      <description>&lt;p&gt;Originally published on Medium:&lt;br&gt;
&lt;a href="https://medium.com/@supsabhi/mastering-pagination-in-jetpack-compose-paging-3-vs-snapshotflow-8193410eb991?sharedUserId=supsabhi" rel="noopener noreferrer"&gt;https://medium.com/@supsabhi/mastering-pagination-in-jetpack-compose-paging-3-vs-snapshotflow-8193410eb991?sharedUserId=supsabhi&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’ve all been there: a list of 1,000 items and a phone that wants to explode. Scrolling through a never-ending list is one of the most common patterns in modern apps: feeds, product lists, chats, you name it. If you’ve ever tried to load thousands of items in a Jetpack Compose list, you know the struggle. Your app starts lagging, memory usage skyrockets, and suddenly your smooth, modern UI feels like it’s running on a potato. That’s where pagination comes to the rescue. Pagination isn’t just a feature; it’s a performance necessity.&lt;/p&gt;

&lt;p&gt;If you’re building with Jetpack Compose today, you essentially have two main ways to handle this: lean on the robust Paging 3 library or roll your own pagination using tools like snapshotFlow and LazyColumn.&lt;br&gt;
In this article, we’ll walk through both approaches, look at real code, and discuss when each one makes sense for your app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Pagination Matters in Modern Android Apps&lt;/strong&gt;&lt;br&gt;
Before we dive into the how, let’s talk about the why. Imagine you’re building a social media app with thousands of posts, or an e-commerce app with endless product listings. Loading everything at once would be a disaster for your users’ experience and your server’s health.Pagination solves this by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reducing memory consumption by loading data in chunks&lt;/li&gt;
&lt;li&gt;Improving app performance with faster initial load times&lt;/li&gt;
&lt;li&gt;Saving bandwidth by fetching only what users need&lt;/li&gt;
&lt;li&gt;Creating smoother scrolling experiences without janky animations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Compose, pagination revolves around a few key building blocks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LazyColumn / LazyVerticalGrid to render large lists efficiently&lt;/li&gt;
&lt;li&gt;Paging 3 (Pager, PagingSource, PagingData) when you want a robust, scalable solution&lt;/li&gt;
&lt;li&gt;snapshotFlow when you want lightweight, custom pagination behavior without bringing in the whole Paging stack&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Approach 1: Pagination with Paging 3&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Paging 3 is Google’s official library to load and display paged data from local or remote sources. It’s feature-rich, battle-tested, and integrates beautifully with Jetpack Compose. Think of it as the Swiss Army knife of pagination.&lt;/p&gt;

&lt;p&gt;Paging 3 isn’t just about loading data in chunks. It’s a complete ecosystem that handles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automatic loading indicators&lt;/li&gt;
&lt;li&gt;Error handling with retry mechanisms&lt;/li&gt;
&lt;li&gt;Efficient memory management with in-memory caching&lt;/li&gt;
&lt;li&gt;Support for multiple data sources (network, database, or both)&lt;/li&gt;
&lt;li&gt;Seamless integration with Room database&lt;/li&gt;
&lt;li&gt;Handling of data transformations and separators&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While using Paging 3, you generally work with three main pieces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PagingSource: Knows how to load a single page of data&lt;/li&gt;
&lt;li&gt;Pager: Wraps your PagingSource and exposes a Flow&amp;gt;&lt;/li&gt;
&lt;li&gt;collectAsLazyPagingItems(): Turns that PagingData flow into something your LazyColumn can consume in Compose&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Setting Up Paging 3&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, add the necessary dependencies to your build.gradle.kts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gradle"&gt;&lt;code&gt;&lt;span class="n"&gt;dependencies&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;implementation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"androidx.paging:paging-runtime:3.2.1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;implementation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"androidx.paging:paging-compose:3.2.1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Creating a PagingSource&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The PagingSource is where the magic begins. It’s responsible for loading pages of data from your data source. Here’s a real-world example fetching user data from an API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserPagingSource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;apiService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ApiService&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;PagingSource&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="n"&gt;suspend&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;LoadParams&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;LoadResult&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
            &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;apiService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUsers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;pageSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;params&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loadSize&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nc"&gt;LoadResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Page&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;prevKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;nextKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isEmpty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;LoadResult&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getRefreshKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;PagingState&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;anchorPosition&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;let&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;anchorPosition&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;closestPageToPosition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;anchorPosition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prevKey&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;plus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;closestPageToPosition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;anchorPosition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nextKey&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;minus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Few points to understand here are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;load() is called automatically when more data is needed&lt;/li&gt;
&lt;li&gt;params.key represents the page number (null for the first load)&lt;/li&gt;
&lt;li&gt;prevKey and nextKey tell Paging 3 how to navigate between pages&lt;/li&gt;
&lt;li&gt;getRefreshKey() determines where to restart loading after a refresh&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Implementing the Repository&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a repository to expose the paging data as a Flow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserRepository&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;apiService&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ApiService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getUsersStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Flow&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;PagingData&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Pager&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PagingConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="n"&gt;pageSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;enablePlaceholders&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;prefetchDistance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;pagingSourceFactory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;UserPagingSource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apiService&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flow&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Few points to understand here are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;enablePlaceholders: Whether to show placeholders for unloaded content&lt;/li&gt;
&lt;li&gt;pageSize: How many items to load per page&lt;/li&gt;
&lt;li&gt;prefetchDistance: How many items before the end should trigger loading&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;ViewModel Integration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your ViewModel should expose the paging data and manage the UI state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserViewModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;UserRepository&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ViewModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;usersFlow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Flow&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;PagingData&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUsersStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cachedIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;viewModelScope&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;cachedIn()&lt;/strong&gt; operator is crucial — it caches the PagingData in the ViewModel scope, preventing unnecessary reloads during configuration changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementation of Compose Part in Screen&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Composable&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nc"&gt;UserListScreen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;UserViewModel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;usersFlow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collectAsLazyPagingItems&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="nc"&gt;LazyColumn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;modifier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Modifier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fillMaxSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;contentPadding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PaddingValues&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;verticalArrangement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Arrangement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;spacedBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;itemCount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;let&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
                &lt;span class="nc"&gt;UserListItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loadState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;refresh&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;LoadState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Loading&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nc"&gt;Box&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                        &lt;span class="n"&gt;modifier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Modifier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fillMaxWidth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="n"&gt;contentAlignment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Alignment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Center&lt;/span&gt;
                    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="nc"&gt;CircularProgressIndicator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loadState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;refresh&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;LoadState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Error&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loadState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;refresh&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;LoadState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;
                &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nc"&gt;ErrorItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                        &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;localizedMessage&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="s2"&gt;"Unknown error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="n"&gt;onRetry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;retry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
                    &lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loadState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;LoadState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Loading&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nc"&gt;Box&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                        &lt;span class="n"&gt;modifier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Modifier&lt;/span&gt;
                            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fillMaxWidth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="n"&gt;contentAlignment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Alignment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Center&lt;/span&gt;
                    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="nc"&gt;CircularProgressIndicator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loadState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="nc"&gt;LoadState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Error&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loadState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;LoadState&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;
                &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nc"&gt;ErrorItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                        &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;localizedMessage&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="s2"&gt;"Unknown error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="n"&gt;onRetry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;retry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
                    &lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can implement some advanced features like inserting separators and &lt;strong&gt;multi-layer caching&lt;/strong&gt; of data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Things to Take Care of While Using Paging 3&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Not Using cachedIn() with Paging 3: Without cachedIn(), you’ll reload data on every configuration change.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Forgetting Error States: Always handle errors gracefully with retry options.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Loading Too Much Data Per Page: Sweet spot: 20–30 items per page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Not Using Stable Keys: Always provide stable, unique keys.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Let’s Deep Dive into Approach 2: SnapshotFlow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sometimes you don’t need the full power of Paging 3. For smaller or simpler lists, or when you want tight control over behavior, you can implement pagination yourself using LazyColumn and snapshotFlow.&lt;br&gt;
snapshotFlow offers a &lt;strong&gt;lightweight, Compose-native&lt;/strong&gt; approach.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Choose SnapshotFlow?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SnapshotFlow is perfect when you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have a simpler pagination requirement&lt;/li&gt;
&lt;li&gt;Want complete control over the loading logic&lt;/li&gt;
&lt;li&gt;Don’t need complex caching mechanisms&lt;/li&gt;
&lt;li&gt;Prefer a minimalist approach without additional dependencies&lt;/li&gt;
&lt;li&gt;Are working with local data sources&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What is snapshotFlow?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;snapshotFlow converts Compose state reads into a cold Flow, emitting a new value whenever that state changes. It’s usually used inside a LaunchedEffect to observe state changes like scroll positions, current page, or user inputs.&lt;/p&gt;

&lt;p&gt;snapshotFlow is great when you need a continuous stream of updates and want to take advantage of Flow operators like debounce, map, or distinctUntilChanged&lt;/p&gt;

&lt;p&gt;How to implement pagination using snapshotFlow is shown in detail in github repository.&lt;br&gt;
&lt;a href="https://github.com/supsabhi/Pagination_jetpackCompose.git" rel="noopener noreferrer"&gt;https://github.com/supsabhi/Pagination_jetpackCompose.git&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Paging 3 vs snapshotFlow/manual: which one should you use?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Both approaches are valid, and you’ll probably use each of them in different parts of the same app.&lt;/p&gt;

&lt;p&gt;Choose Paging 3 When:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need robust error handling and retry mechanisms out of the box&lt;/li&gt;
&lt;li&gt;Your app requires offline-first functionality with Room database&lt;/li&gt;
&lt;li&gt;You want automatic loading state management&lt;/li&gt;
&lt;li&gt;You’re dealing with complex multi-source data (network + database)&lt;/li&gt;
&lt;li&gt;You need features like data transformations and separators&lt;/li&gt;
&lt;li&gt;You prefer battle-tested, officially supported solutions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Choose SnapshotFlow When:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You have simple pagination requirements&lt;/li&gt;
&lt;li&gt;You want minimal dependencies and a smaller APK size&lt;/li&gt;
&lt;li&gt;You need complete control over loading logic&lt;/li&gt;
&lt;li&gt;You’re comfortable managing loading states manually&lt;/li&gt;
&lt;li&gt;You’re working primarily with in-memory data&lt;/li&gt;
&lt;li&gt;You want a pure Compose solution without additional libraries&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Wrapping Up&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Pagination in Jetpack Compose doesn’t have to be intimidating. Whether you choose the comprehensive Paging 3 library or the lightweight snapshotFlow approach, you now have the tools to implement smooth, efficient pagination in your apps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quick recap:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Paging 3 for complex, production apps with multiple data sources&lt;/li&gt;
&lt;li&gt;Use snapshotFlow for simpler requirements and more control&lt;/li&gt;
&lt;li&gt;Always handle loading and error states gracefully&lt;/li&gt;
&lt;li&gt;Optimize with proper keys, caching, and debouncing&lt;/li&gt;
&lt;li&gt;Test your implementation thoroughly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The best approach depends on your specific needs, but with both techniques in your toolkit, you’re ready to handle any pagination challenge that comes your way.&lt;/p&gt;

&lt;p&gt;Now go forth and paginate! Your users (and your app’s performance) will thank you&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub Repository for Hands-On Reference&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To make this article more practical and hands-on, I’ve published a public &lt;strong&gt;GitHub repository&lt;/strong&gt; that demonstrates everything discussed above.&lt;/p&gt;

&lt;p&gt;The goal of this project is not just to “fetch data and display”, but to show how pagination can be done in different ways in an Android application using Ktor,Coin.&lt;/p&gt;

&lt;p&gt;📂 GitHub Repository:&lt;br&gt;
&lt;a href="https://github.com/supsabhi/Pagination_jetpackCompose.git" rel="noopener noreferrer"&gt;https://github.com/supsabhi/Pagination_jetpackCompose.git&lt;/a&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>mobile</category>
      <category>development</category>
      <category>kotlin</category>
    </item>
    <item>
      <title>Beyond One Size Fits All: A Beginner’s Guide to Jetpack WindowManager 1.5.0</title>
      <dc:creator>supriya shah</dc:creator>
      <pubDate>Thu, 19 Nov 2026 09:01:48 +0000</pubDate>
      <link>https://dev.to/supriya_shah_1e9c3df6158c/beyond-one-size-fits-all-a-beginners-guide-to-jetpack-windowmanager-150-5ceg</link>
      <guid>https://dev.to/supriya_shah_1e9c3df6158c/beyond-one-size-fits-all-a-beginners-guide-to-jetpack-windowmanager-150-5ceg</guid>
      <description>&lt;p&gt;Originally published on Medium:&lt;br&gt;
&lt;a href="https://medium.com/@supsabhi/beyond-one-size-fits-all-a-beginners-guide-to-jetpack-windowmanager-1-5-0-fc42532542dc?sharedUserId=supsabhi" rel="noopener noreferrer"&gt;https://medium.com/@supsabhi/beyond-one-size-fits-all-a-beginners-guide-to-jetpack-windowmanager-1-5-0-fc42532542dc?sharedUserId=supsabhi&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the early days of Android, it was only designed for a phone and maybe if an app was required to run on a tablet, then you would tweak a few things for a tablet. Fast forward to 2026, Android screens are no longer simple rectangles; the landscape has changed. Today we have foldables that turn into mini-tablets, dual-screen devices, resizable app windows, and desktop-style windowing on tablets. For apps to look great everywhere, they must adapt. That’s where Jetpack WindowManager comes in.&lt;/p&gt;

&lt;p&gt;Jetpack WindowManager is the Jetpack library that helps your app understand “what kind of window am I running in?” It’s a Jetpack library that:&lt;/p&gt;

&lt;p&gt;Detects folds, hinges, and postures on foldables&lt;br&gt;
Computes window size &amp;amp; metrics&lt;br&gt;
Helps your UI adapt to multi-window and multi-screen environments&lt;br&gt;
While the system knows the screen size, WindowManager tells you about the Window size — which is what actually matters when your app is in split-screen or running on a foldable.&lt;/p&gt;

&lt;p&gt;For Compose apps this means you can:&lt;/p&gt;

&lt;p&gt;Show a single-pane layout on phones, two-pane on tablets, and more complex layouts on big monitors.&lt;br&gt;
React when the user resizes a window in desktop mode or rotates the device.&lt;br&gt;
Handle foldables (e.g., put content on each side of the hinge).&lt;br&gt;
In simple terms: WindowManager gives your app “eyes” to understand the screen layout and how it changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What’s New in Version 1.5.0?&lt;/strong&gt;&lt;br&gt;
The latest 1.5.0 stable release (October 2025) is a big deal because it officially recognizes that “Large” isn’t big enough anymore and it makes the library stable. At a high level, 1.5.0 focuses on better breakpoints, better activity embedding, and more flexible metrics APIs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Changes&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Large &amp;amp; Extra-Large Window Size Classes Before, size classes were roughly Compact / Medium / Expanded. But on desktops and ultra-large screens, even Expanded feels too small — you can fit much more UI. So 1.5.0 adds:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Large: widths ~1200dp to 1600dp&lt;/li&gt;
&lt;li&gt;Extra-large: widths ≥1600dp
This means you can now design layouts that take full advantage of truly big screens.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Application Context Support Previously, you needed an Activity to calculate window metrics. Now, you can do it from the Application context, making it much more flexible for background logic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Auto-Save for Activity Embedding If you use “Activity Embedding” (showing two activities side-by-side), the library now automatically remembers your split state even if the app process is killed and restarted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Better WindowMetrics Support You can calculate window metrics even from the application context, which makes it easier to measure screen/window sizes outside of activities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Easier WindowLayoutInfo Access A direct getter makes accessing layout info smoother and more idiomatic.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;WindowManager + Jetpack Compose: Real Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s see the basic setup for the demo app which will demonstrate the usage of WindowManager.&lt;/p&gt;

&lt;p&gt;Add the dependencies In your build.gradle.kts (module):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gradle"&gt;&lt;code&gt;&lt;span class="n"&gt;dependencies&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;implementation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"androidx.window:window:1.5.0"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;           &lt;span class="c1"&gt;// Core WindowManager&lt;/span&gt;
    &lt;span class="nf"&gt;implementation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"androidx.compose.material3:material3:1.3.0"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Example compose version&lt;/span&gt;
    &lt;span class="nf"&gt;implementation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"androidx.compose.ui:ui:1.7.0"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Use the latest Compose versions that match your project; the important part is androidx.window🪟1.5.0.)&lt;/p&gt;

&lt;p&gt;The rest of the code I have uploaded on GitHub. Please find it on: &lt;a href="https://github.com/supsabhi/Windows-Manager-Demo.git" rel="noopener noreferrer"&gt;https://github.com/supsabhi/Windows-Manager-Demo.git&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Jetpack WindowManager vs WindowSizeClass&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;WindowSizeClass (and its newer adaptive cousins) and WindowManager are related but they sit at different abstraction levels. WindowManager is the low-level source of window information; WindowSizeClass is a friendly, opinionated wrapper that gives you named buckets like compact / medium / expanded.&lt;/p&gt;

&lt;p&gt;WindowManager:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Library: androidx.window:window.&lt;/li&gt;
&lt;li&gt;Provides raw window metrics, folding features, posture, and activity embedding APIs.&lt;/li&gt;
&lt;li&gt;You can define any breakpoints and behavior you want, including the new large / extra-large ranges.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;WindowSizeClass / Adaptive APIs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Built on top of WindowManager’s metrics and breakpoints logic.&lt;/li&gt;
&lt;li&gt;Maps width/height into semantic classes (compact, medium, expanded, large, extra-large) aligned with Material Design guidance.&lt;/li&gt;
&lt;li&gt;Provides helpers like calculateWindowAdaptiveInfo and components like NavigationSuite that auto-adapt.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Final Takeaway&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Jetpack WindowManager lets your app:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understand how the screen is shaped&lt;/li&gt;
&lt;li&gt;Adapt UI across phones, foldables, tablets, and now large/extra-large screens&lt;/li&gt;
&lt;li&gt;Work even better with Compose thanks to the latest 1.5.0 updates&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By using the 1.5.0 updates, you’re future-proofing your app for the next generation of massive “Pro” tablets and desktop-modded Android devices.&lt;/p&gt;

</description>
      <category>android</category>
      <category>mobile</category>
      <category>androiddev</category>
    </item>
    <item>
      <title>Mastering GraphQL with Ktor: A Modern Networking Guide for Android</title>
      <dc:creator>supriya shah</dc:creator>
      <pubDate>Mon, 29 Jun 2026 13:15:01 +0000</pubDate>
      <link>https://dev.to/supriya_shah_1e9c3df6158c/mastering-graphql-with-ktor-a-modern-networking-guide-for-android-1nc5</link>
      <guid>https://dev.to/supriya_shah_1e9c3df6158c/mastering-graphql-with-ktor-a-modern-networking-guide-for-android-1nc5</guid>
      <description>&lt;p&gt;Originally published on Medium:&lt;br&gt;
&lt;a href="https://medium.com/@supsabhi/mastering-graphql-with-ktor-a-modern-networking-guide-for-android-028f388836ed?sharedUserId=supsabhi" rel="noopener noreferrer"&gt;https://medium.com/@supsabhi/mastering-graphql-with-ktor-a-modern-networking-guide-for-android-028f388836ed?sharedUserId=supsabhi&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Modern Android apps demand flexible, efficient and scalable networking solutions. While REST APIs have been the standard for years, GraphQL has emerged as a powerful alternative ,especially for apps that need precise data fetching and reduced network overhead. Instead of hitting multiple endpoints to get different pieces of data, GraphQL allows you to ask for exactly what you need in a single request.&lt;/p&gt;

&lt;p&gt;In my &lt;strong&gt;previous article&lt;/strong&gt;, I discussed how to set up &lt;strong&gt;Ktor&lt;/strong&gt;, the modern Kotlin-first networking framework developed by JetBrains. We explored how it provides a lightweight alternative to Retrofit. If you haven’t read that yet, I highly recommend checking it out to get your base client set up.You can find the article here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@supsabhi/exploring-ktor-a-modern-networking-framework-for-kotlin-462e6769a721" rel="noopener noreferrer"&gt;https://medium.com/@supsabhi/exploring-ktor-a-modern-networking-framework-for-kotlin-462e6769a721&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let’s take things a step further and explore how you can &lt;strong&gt;integrate GraphQL with Ktor&lt;/strong&gt; to build efficient APIs. Whether you are a beginner or looking to modernize your stack, this guide will cover everything from setup to making your first request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is GraphQL?&lt;/strong&gt;&lt;br&gt;
GraphQL is a query language for APIs that allows the client to request exactly the data it needs ,nothing more nothing less.&lt;/p&gt;

&lt;p&gt;The major difference is that REST uses multiple endpoints with fixed response structures, while GraphQL uses a single endpoint with flexible queries to give optimized responses. This bandwidth efficiency is perfect for mobile apps where every kilobyte counts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Use GraphQL with Ktor?&lt;/strong&gt;&lt;br&gt;
Using Ktor for GraphQL gives you:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Minimal Overhead: No need for heavy external libraries,keep your APK size small.&lt;/li&gt;
&lt;li&gt;Full Control: You define exactly how the request and response are handled.&lt;/li&gt;
&lt;li&gt;Multiplatform Ready: The same logic works seamlessly in Kotlin Multiplatform (KMP).&lt;/li&gt;
&lt;li&gt;Kotlin-First: Coroutine-based, no callbacks, and works smoothly with Clean Architecture &amp;amp; MVVM&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Setting Up the Project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before integrating GraphQL, ensure you have Ktor in your Android project. Add these dependencies to your app-level build.gradle.kts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gradle"&gt;&lt;code&gt;&lt;span class="k"&gt;dependencies&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;implementation&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;platform&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"io.ktor:ktor-bom:3.1.2"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;implementation&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"io.ktor:ktor-client-android"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;implementation&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"io.ktor:ktor-client-content-negotiation"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;implementation&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"io.ktor:ktor-serialization-kotlinx-json"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;implementation&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"io.ktor:ktor-client-logging"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ensure the &lt;strong&gt;Kotlin Serialization&lt;/strong&gt; plugin is enabled in your root build.gradle.kts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight gradle"&gt;&lt;code&gt;&lt;span class="n"&gt;plugins&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"org.jetbrains.kotlin.plugin.serialization"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="s2"&gt;"2.1.20"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Understanding How GraphQL Works with Ktor&lt;/strong&gt;&lt;br&gt;
With GraphQL, every operation is usually a POST request to a single endpoint. The query or mutation is passed as a JSON body.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Define the Request Model&lt;/strong&gt;&lt;br&gt;
First, create a data model to wrap your query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;
&lt;span class="nd"&gt;@Serializable&lt;/span&gt;
&lt;span class="kd"&gt;data class&lt;/span&gt; &lt;span class="nc"&gt;GraphQLRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;variables&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;?&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Define the Generic Response Wrapper&lt;/strong&gt;&lt;br&gt;
GraphQL always returns data inside a data field and errors inside an errors field.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Serializable&lt;/span&gt;
&lt;span class="kd"&gt;data class&lt;/span&gt; &lt;span class="nc"&gt;GraphQLResponse&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;T&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;GraphQLError&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;?&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@Serializable&lt;/span&gt;
&lt;span class="kd"&gt;data class&lt;/span&gt; &lt;span class="nc"&gt;GraphQLError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Making Your First Request&lt;/strong&gt;&lt;br&gt;
Let’s fetch a list of countries using a public GraphQL API. First, define your data models:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Serializable&lt;/span&gt;
&lt;span class="kd"&gt;data class&lt;/span&gt; &lt;span class="nc"&gt;CountriesData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;countries&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Country&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@Serializable&lt;/span&gt;
&lt;span class="kd"&gt;data class&lt;/span&gt; &lt;span class="nc"&gt;Country&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;emoji&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;capital&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;br&gt;
Here is how you execute the query using the httpClient we created in the previous article:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;suspend&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;fetchCountries&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nc"&gt;GraphQLResponse&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;CountriesData&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;countryQuery&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"""
        query {
            countries {
                code
                name
                emoji
                capital
            }
        }
    """&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trimIndent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;


&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;httpClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"https://countries.trevorblades.com/graphql"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;setBody&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;GraphQLRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;countryQuery&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;}.&lt;/span&gt;&lt;span class="nf"&gt;body&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Handling Errors and Logging&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;GraphQL can return an HTTP 200 status even if there are errors in the query logic. Always check the error list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;response&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fetchCountries&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isNullOrEmpty&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;
        &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;e&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"GraphQL Error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For professional logging, I recommend using &lt;strong&gt;Timber&lt;/strong&gt;. I’ve written a &lt;strong&gt;detailed guide&lt;/strong&gt; on setting it up here: Effortless Android &lt;strong&gt;Logging with Timber and Kotlin.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Integrating GraphQL with Ktor is straightforward and gives Android developers a &lt;strong&gt;modern&lt;/strong&gt;, &lt;strong&gt;flexible&lt;/strong&gt; and &lt;strong&gt;Kotlin-native networking stack&lt;/strong&gt;. It fits beautifully with MVVM and Clean Architecture. By leveraging one unified HttpClient, you can now handle both REST and GraphQL seamlessly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub Repository for Hands-On Reference&lt;/strong&gt;&lt;br&gt;
To make this article more practical and hands-on, I’ve &lt;strong&gt;published&lt;/strong&gt; a public &lt;strong&gt;GitHub repository&lt;/strong&gt; that demonstrates everything discussed above using a real GraphQL API.&lt;/p&gt;

&lt;p&gt;The goal of this project is not just to “fetch data”, but to show how GraphQL should be integrated idiomatically in an Android application using Ktor, without forcing REST-based abstractions on top of it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📂 GitHub Repository:&lt;br&gt;
&lt;a href="https://github.com/supsabhi/GraphQL_example.git" rel="noopener noreferrer"&gt;https://github.com/supsabhi/GraphQL_example.git&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>mobile</category>
      <category>networking</category>
      <category>graphql</category>
    </item>
    <item>
      <title>The Beginner’s Guide to State Collection in Jetpack Compose</title>
      <dc:creator>supriya shah</dc:creator>
      <pubDate>Mon, 29 Jun 2026 13:03:49 +0000</pubDate>
      <link>https://dev.to/supriya_shah_1e9c3df6158c/the-beginners-guide-to-state-collection-in-jetpack-compose-4bng</link>
      <guid>https://dev.to/supriya_shah_1e9c3df6158c/the-beginners-guide-to-state-collection-in-jetpack-compose-4bng</guid>
      <description>&lt;p&gt;Originally published on Medium:&lt;br&gt;
&lt;a href="https://medium.com/@supsabhi/the-beginners-guide-to-state-collection-in-jetpack-compose-92662afe3e44?sharedUserId=supsabhi" rel="noopener noreferrer"&gt;https://medium.com/@supsabhi/the-beginners-guide-to-state-collection-in-jetpack-compose-92662afe3e44?sharedUserId=supsabhi&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How to Collect State in Jetpack Compose Without Draining the Battery?
&lt;/h2&gt;

&lt;p&gt;In the journey of learning Jetpack Compose, you’ve likely encountered a common challenge: How to get my data from my ViewModel into my UI?&lt;/p&gt;

&lt;p&gt;In the world of Android, we usually use Flow to stream data. But Compose speaks “State.” To bridge that gap, we use two popular tools: collectAsState() and collectAsStateWithLifecycle().&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;collectAsState()&lt;/strong&gt; and &lt;strong&gt;collectAsStateWithLifecycle()&lt;/strong&gt; both listen to a Flow (or StateFlow) from your ViewModel and turn it into Compose State so your UI can automatically recompose.&lt;/p&gt;

&lt;p&gt;While they look almost identical, choosing the wrong one can lead to resource leaks or unexpected behavior of an app. Let’s break them down in a simple real world way.&lt;/p&gt;

&lt;p&gt;What &lt;strong&gt;collectAsState()&lt;/strong&gt; does&lt;br&gt;
Think of collectAsState() as a loyal friend who never stops listening to you. As soon as your Composable is on the screen, it starts “collecting” data from your Flow and turning it into a State object that Compose can read.It stops collecting when the composable leaves the composition (when you navigate away or the composable is removed).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Catch:&lt;/strong&gt; This friend is too loyal. If the user minimizes your app to check a text message, collectAsState() keeps listening to that data stream in the background.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros: Simple, built into the core Compose library.&lt;/strong&gt;&lt;br&gt;
Cons: It keeps the “pipe” open even when the user can’t see the app.your Flow keeps emitting and your ViewModel keeps doing work,which drains the battery and consumes resources unnecessarily.&lt;br&gt;
How to use collectAsState()&lt;br&gt;
You don’t need any extra lifecycle libraries for this one, as it comes built-in with the standard Compose runtime.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Composable&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;UserProfile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;MyViewModel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;uiState&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;userFlow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collectAsState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello, ${uiState.name}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What &lt;strong&gt;collectAsStateWithLifecycle()&lt;/strong&gt; adds&lt;br&gt;
This is the &lt;strong&gt;“Android-aware”&lt;/strong&gt; version of the collector. collectAsStateWithLifecycle() behaves like collectAsState(), but also respects the Android lifecycle of the screen/activity.It doesn’t just listen blindly; it watches the Lifecycle of your app.&lt;/p&gt;

&lt;p&gt;When the user moves away from the app (putting it in the background), collectAsStateWithLifecycle() says, “Since nobody is looking at the screen, I’m going to stop collecting for a bit to save energy.” As soon as the user comes back, it picks right up where it left off.&lt;/p&gt;

&lt;p&gt;This means less wasted work, fewer unnecessary emissions, and safer behavior during configuration changes and navigation.&lt;/p&gt;

&lt;p&gt;Why this matters: If your Flow is connected to a database or a location sensor, keeping it active in the background is a silent performance killer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to use it in your code&lt;/strong&gt;&lt;br&gt;
To use the lifecycle-aware version, make sure you have the lifecycle-runtime-compose dependency in your build.gradle file. Then, it’s as simple as this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Composable&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;UserProfile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;MyViewModel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;uiState&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;userFlow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collectAsStateWithLifecycle&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello, ${uiState.name}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;br&gt;
So basically we can say that the big difference between two of them is that collectAsStateWithLifecycle() is lifecycle-aware at the Android level, while collectAsState() only follows the composable’s own lifecycle, which can waste resources when the app goes to the background.&lt;/p&gt;

&lt;p&gt;You can think of it this way:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“I want my screen to stay in sync with the Flow only while the user can actually see it.”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That sentence describes collectAsStateWithLifecycle() almost perfectly.&lt;/p&gt;

&lt;p&gt;👏 Found this helpful?&lt;/p&gt;

&lt;p&gt;Are you still using the standard collectAsState() in your Android projects, or have you already made the switch to the lifecycle-aware version?&lt;/p&gt;

&lt;p&gt;If you found this helpful, hit the 👏 clap button and follow for more beginner-friendly Jetpack Compose tips!💬 Questions or suggestions? Drop a comment below — I read and respond to every one!&lt;/p&gt;

&lt;p&gt;🔄 Share this article with fellow Android developers who might find it useful.&lt;/p&gt;

&lt;p&gt;Happy coding! 🚀&lt;/p&gt;

</description>
      <category>android</category>
      <category>mobile</category>
      <category>coding</category>
      <category>development</category>
    </item>
    <item>
      <title>Jetpack Compose: remember vs rememberSaveable</title>
      <dc:creator>supriya shah</dc:creator>
      <pubDate>Mon, 23 Mar 2026 09:09:36 +0000</pubDate>
      <link>https://dev.to/supriya_shah_1e9c3df6158c/jetpack-compose-remember-vs-remembersaveable-131o</link>
      <guid>https://dev.to/supriya_shah_1e9c3df6158c/jetpack-compose-remember-vs-remembersaveable-131o</guid>
      <description>&lt;p&gt;Originally published on Medium:&lt;br&gt;
&lt;a href="https://medium.com/@supsabhi/jetpack-compose-remember-vs-remembersaveable-75ff37f8047e" rel="noopener noreferrer"&gt;https://medium.com/@supsabhi/jetpack-compose-remember-vs-remembersaveable-75ff37f8047e&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it is?When to Use? your beginner friendly guide&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine this: You’re filling out a login form on your Android app, typing your email and password carefully. Just as you’re about to hit submit, you accidentally rotate your phone. Poof! All your entered data disappears, and you have to start over. Frustrating, right?&lt;/p&gt;

&lt;p&gt;This common scenario highlights one of the most crucial concepts in modern Android development with Jetpack Compose: state management.&lt;/p&gt;

&lt;p&gt;When building Android apps with Jetpack Compose, managing state is one of the most important tasks you’ll encounter.&lt;/p&gt;

&lt;p&gt;Whether you’re a beginner just starting your journey in Compose or an experienced developer looking to deepen your understanding, mastering remember() and rememberSaveable() is essential to make apps UI interactive and responsive to user actions. Keeping track of UI information — like user inputs, button clicks, or toggle switches — ensures your app behaves reliably and smoothly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is “State” in Simple Terms?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think of state as your app’s memory.In UI programming, state is just information your app needs to “remember” to correctly show the screen. For example:&lt;/p&gt;

&lt;p&gt;The current text in a search box.&lt;br&gt;
How many times a button has been clicked.&lt;br&gt;
Whether a switch is on or off.&lt;br&gt;
In a counter app, the current number is the state.&lt;br&gt;
In a shopping cart, the list of items and total price represent state.&lt;br&gt;
When this information changes, the UI updates to reflect it. &lt;strong&gt;Jetpack Compose&lt;/strong&gt; uses mutable state objects like mutableStateOf() to track these changes reactively.&lt;/p&gt;

&lt;p&gt;In short it’s any data that can change over time and affects what users see on their screen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-world analogy:&lt;/strong&gt; &lt;em&gt;State is like the current page number in a book you’re reading. As you progress through the book (interact with your app), the page number (state) changes, and this determines what content you see.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In traditional Android development with XML layouts, managing state was complex and error-prone. Jetpack Compose revolutionizes this by making UI a function of state. When state changes, the UI automatically updates to reflect those changes.&lt;/p&gt;

&lt;p&gt;Recomposition is Compose’s way of updating the UI when state changes. Jetpack Compose UI functions can be called multiple times (this is called recomposition).Think of it as automatically redrawing parts of your screen when something changes. However, there’s a catch: during recomposition, local variables get reset to their initial values unless we use special state holders.&lt;/p&gt;

&lt;p&gt;Without remember, every time your UI recomposes, your variable would reset to its initial state, losing any user input or interaction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is remember()?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;remember() is a Compose function that stores a value in memory during composition and returns the same value across recompositions. It’s like giving your Composable function a short-term.It saves the state in a temporary bundle behind the scenes, so user input or important UI state remains even after an activity is recreated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is rememberSaveable()?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;rememberSaveable() is like remember() with superpowers. It not only stores values across recompositions but also survives configuration changes like screen rotation, theme changes, and even process death in some cases. rememberSaveable uses Android’s SavedStateHandle behind the scenes, storing state in a bundle, so it can survive these changes automatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Differs from remember()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The key difference lies in persistence:&lt;/p&gt;

&lt;p&gt;remember(): Survives recomposition only&lt;br&gt;
rememberSaveable(): Survives recomposition + configuration changes&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use remember() when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Temporary UI state&lt;/strong&gt;: Button pressed states, animation values, scroll positions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Derived state&lt;/strong&gt;: Calculated values that can be easily recomputed&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance-critical scenarios&lt;/strong&gt;: High-frequency updates where serialization overhead matters&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Large objects&lt;/strong&gt;: Complex objects that don’t need to survive configuration changes&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Use rememberSaveable() when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;User input&lt;/strong&gt;: Form fields, search queries, text input&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Important user progress&lt;/strong&gt;: Game scores, shopping cart contents&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;User preferences&lt;/strong&gt;: Selected options, filter settings&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Navigation state&lt;/strong&gt;: Selected tabs, current page indices&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Not managing state correctly can lead to frustrating UX, where your app forgets what the user was doing,your UI becomes essentially broken. Variables reset on every recomposition, and changes don’t trigger UI updates.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;One of the common misconception: “My composable only runs once.” In reality, composables can recompose many times.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Always assume your composable function will be called multiple times. That’s why below best practices are very much important&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;State hoisting&lt;/strong&gt;: Keep state at the lowest common parent&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Single source of truth&lt;/strong&gt;: Don’t duplicate state across composables&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Immutable state&lt;/strong&gt;: Use immutable data classes when possible&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Avoid side effects in composition&lt;/strong&gt;: Use LaunchedEffect or DisposableEffect&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Test configuration changes&lt;/strong&gt;: Always test your app by rotating the device&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Pro tip: For large datasets, save only the essential identifier (like a selected ID) in rememberSaveable() and recreate the full object using remember().&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Below is a Simple Example Showing the Difference&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Composable&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;WithoutRememberExample&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="py"&gt;text&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;mutableStateOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nc"&gt;TextField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;onValueChange&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="n"&gt;label&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Type something"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, every time Composable redraws (recomposes), text gets reset to empty, so any input is lost immediately — even when you type a character. The UI isn’t interactive at all because it never “remembers” what you typed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Composable&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;RememberExample&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="py"&gt;text&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="nf"&gt;remember&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;mutableStateOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;TextField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;onValueChange&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="n"&gt;label&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Type something"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the typed text is remembered only when the UI updates.&lt;/p&gt;

&lt;p&gt;But if you rotate the screen, text will reset to empty.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Composable&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;RememberSaveableExample&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="py"&gt;text&lt;/span&gt; &lt;span class="k"&gt;by&lt;/span&gt; &lt;span class="nf"&gt;rememberSaveable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;mutableStateOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;TextField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;onValueChange&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="n"&gt;label&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Type something"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, text will still hold after device rotation or UI recreation.&lt;/p&gt;

&lt;p&gt;Understanding the difference between remember() and rememberSaveable() is crucial for building robust, user-friendly Android applications.Remember, becoming proficient with Compose state management takes practice.Start with simple examples and you will reach there sooner.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;👏 Found this helpful?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If this article helped you understand Jetpack Compose state management, please give it a clap and follow me for more Android development tutorials!&lt;/p&gt;

&lt;p&gt;💬 Questions or suggestions? Drop a comment below — I read and respond to every one!&lt;/p&gt;

&lt;p&gt;🔄 Share this article with fellow Android developers who might find it useful.&lt;/p&gt;

&lt;p&gt;Happy coding! 🚀&lt;/p&gt;

</description>
      <category>android</category>
      <category>mobile</category>
      <category>programming</category>
      <category>performance</category>
    </item>
    <item>
      <title>Lazy Grids in Jetpack Compose</title>
      <dc:creator>supriya shah</dc:creator>
      <pubDate>Tue, 17 Mar 2026 05:43:46 +0000</pubDate>
      <link>https://dev.to/supriya_shah_1e9c3df6158c/lazy-grids-in-jetpack-compose-4973</link>
      <guid>https://dev.to/supriya_shah_1e9c3df6158c/lazy-grids-in-jetpack-compose-4973</guid>
      <description>&lt;p&gt;Originally published on Medium: &lt;br&gt;
&lt;a href="https://medium.com/@supsabhi/lazy-grids-in-jetpack-compose-8a80f52421c9" rel="noopener noreferrer"&gt;https://medium.com/@supsabhi/lazy-grids-in-jetpack-compose-8a80f52421c9&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧩 Mastering Grids in easy way&lt;/strong&gt;&lt;br&gt;
Ever opened an app and felt overwhelmed by a long, never-ending list? Or maybe you’ve needed to show a bunch of beautiful photos or product cards without cramming them into a tiny space?&lt;/p&gt;

&lt;p&gt;You know, the ones that scroll vertically and show these items one after another. But what if you want to show these items side by side, like a gallery, product catalog, or contact cards?&lt;/p&gt;

&lt;p&gt;That’s where the mighty Grid Layout comes in to save the day!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🏛 Classic Android Grids&lt;/strong&gt;&lt;br&gt;
In classic Android (XML days), developers often used:&lt;/p&gt;

&lt;p&gt;GridLayout or RecyclerView with GridLayoutManager for arranging UI components&lt;br&gt;
GridView for bigger, scrollable lists — like image thumbnails or product tiles in shopping apps&lt;br&gt;
💡 So… what exactly is a Grid Layout?&lt;br&gt;
A Grid is like a shelf with rows and columns.&lt;br&gt;
It’s a way to organize items into rows and columns so everything is neat, tidy, and easy to find.&lt;/p&gt;

&lt;p&gt;We use grid layouts whenever we need to display a collection of items that are:&lt;/p&gt;

&lt;p&gt;Visually Similar — Like a gallery of product images or thumbnails&lt;br&gt;
Equal in Importance — Unlike a news feed where the top item is most important, items in a grid usually hold similar weight&lt;br&gt;
High in Quantity — It’s a much better use of screen space than a vertical list when you have dozens of things to show&lt;br&gt;
⚡ Jetpack Compose Grids Got Lazy!&lt;br&gt;
In Jetpack Compose, there are mainly two ways to arrange items:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. GridLayout&lt;/strong&gt;&lt;br&gt;
Good for static, small-to-medium datasets&lt;br&gt;
Builds the whole UI upfront, so if you have a lot of items, it may slow things down&lt;br&gt;
Best for forms or dashboards where all elements should be shown at once&lt;br&gt;
No built-in “lazy loading” here&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Lazy Lists &amp;amp; Lazy Grids&lt;/strong&gt;&lt;br&gt;
Smart approach — only composes what’s visible on screen&lt;br&gt;
Includes LazyColumn (for vertical lists) and LazyVerticalGrid (for grids)&lt;br&gt;
Only creates as many views as fit on the screen plus a few extra for smooth scrolling&lt;br&gt;
Fast and memory-friendly, especially for huge lists&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧠 LazyList vs LazyGrid — When to Use What?&lt;/strong&gt;&lt;br&gt;
Both LazyLists and LazyGrids are “lazy” because they only load the items currently visible on screen, saving battery and memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🪄 LazyList (LazyColumn, LazyRow)&lt;/strong&gt;&lt;br&gt;
Displays items one after another (vertically or horizontally)&lt;br&gt;
Shows sequential content, so each item takes one entire row or column&lt;br&gt;
Perfect for feeds, chat screens, or any single-column list&lt;br&gt;
&lt;strong&gt;🧩 LazyGrid (LazyVerticalGrid, LazyHorizontalGrid)&lt;/strong&gt;&lt;br&gt;
Displays items in rows and columns, forming a neat grid layout&lt;br&gt;
Shows content in a collection manner, so each item takes up one cell in the grid&lt;br&gt;
Perfect for e-commerce product grids, image galleries, or dashboards&lt;br&gt;
🧰 Types of Grids in Jetpack Compose&lt;br&gt;
Jetpack Compose provides two main grid types out of the box:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LazyVerticalGrid&lt;/strong&gt;&lt;br&gt;
Scrolls vertically, items arranged in columns&lt;br&gt;
Think of your phone’s photo gallery&lt;br&gt;
LazyHorizontalGrid&lt;/p&gt;

&lt;p&gt;Scrolls horizontally, items arranged in column&lt;br&gt;
Also great for galleries or horizontally scrolling product carousels&lt;br&gt;
Both work exactly like LazyColumn or LazyRow, but with the magic of multiple columns or rows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🚀 Quick Example: LazyVerticalGrid&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nc"&gt;LazyVerticalGrid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;columns&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;GridCells&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Fixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 3 columns&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;
        &lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Item $index"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;modifier&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Modifier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;columns = GridCells.Fixed(3) → We’re asking for 3 fixed columns&lt;br&gt;
Want an adaptive grid that fits as many columns as possible with at least 100dp width?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nc"&gt;LazyVerticalGrid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;columns&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;GridCells&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Adaptive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;minSize&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="p"&gt;-&amp;gt;&lt;/span&gt;
        &lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Adaptive $index"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;modifier&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Modifier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dp&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🧩 GridCells Properties — The Secret Sauce&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The real power of LazyVerticalGrid lies in how you define its columns using the GridCells object.&lt;/p&gt;

&lt;p&gt;Here are the main ways:&lt;/p&gt;

&lt;p&gt;GridCells.Fixed(count) — Sets an exact number of columns. Use when you always want, say, 3 columns, no matter the screen size (great for photo galleries)&lt;br&gt;
GridCells.Adaptive(minSize) — Creates as many columns as will fit, ensuring each column is at least a certain size. Makes your grid responsive across devices&lt;br&gt;
GridCells.FixedSize(size) — Sets an exact width for each column and fills the screen. Less common, but useful for rigid layouts&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🏁 Final Thoughts&lt;/strong&gt;&lt;br&gt;
Lazy Grids in Jetpack Compose are a total game-changer for displaying items in a flexible, scrollable grid — without dealing with RecyclerView adapters or XML layouts.&lt;/p&gt;

&lt;p&gt;They’re powerful, adaptive, and super easy to use. Once you try them, you’ll never want to go back.&lt;/p&gt;

&lt;p&gt;So go ahead — build that gallery, product grid, or dashboard with LazyVerticalGrid and let Compose handle the heavy lifting! 🚀&lt;/p&gt;

&lt;p&gt;Grid layouts are everywhere in Android, and Jetpack Compose’s Lazy grids make building them for modern apps super easy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;💡 Detailed source code and more Compose examples are available on my GitHub — check it out and explore!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/supsabhi/GridLayoutDemo.git" rel="noopener noreferrer"&gt;https://github.com/supsabhi/GridLayoutDemo.git&lt;/a&gt;&lt;/p&gt;

</description>
      <category>android</category>
      <category>mobile</category>
      <category>jetpack</category>
      <category>development</category>
    </item>
    <item>
      <title>Build a Cross-Platform QR Code Scanner in .NET MAUI using ZXing.Net.MAUI</title>
      <dc:creator>supriya shah</dc:creator>
      <pubDate>Fri, 06 Feb 2026 07:12:32 +0000</pubDate>
      <link>https://dev.to/supriya_shah_1e9c3df6158c/build-a-cross-platform-qr-code-scanner-in-net-maui-using-zxingnetmaui-5993</link>
      <guid>https://dev.to/supriya_shah_1e9c3df6158c/build-a-cross-platform-qr-code-scanner-in-net-maui-using-zxingnetmaui-5993</guid>
      <description>&lt;p&gt;Originally published on Medium:&lt;br&gt;
&lt;a href="https://medium.com/@supsabhi/build-a-cross-platform-qr-code-scanner-in-net-maui-using-zxing-net-maui-5638b479372d" rel="noopener noreferrer"&gt;https://medium.com/@supsabhi/build-a-cross-platform-qr-code-scanner-in-net-maui-using-zxing-net-maui-5638b479372d&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A step-by-step beginner’s guide to integrating QR and barcode scanning easily in your MAUI app&lt;/strong&gt;&lt;br&gt;
If you want to build a &lt;strong&gt;cross-platform app with QR code scanning in .NET MAUI&lt;/strong&gt;, there are several ways to do it. You can use libraries like &lt;strong&gt;ZXing.Net.Maui.Controls, Camera.MAUI, IronQR, or Google Vision ML Kit.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Each has its own strengths:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;- &lt;strong&gt;ZXing&lt;/strong&gt; is open-source and widely adopted.&lt;/li&gt;
&lt;li&gt;- &lt;strong&gt;IronQR&lt;/strong&gt; offers a simple and commercial-ready cross-platform library.&lt;/li&gt;
&lt;li&gt;- &lt;strong&gt;Google Vision ML Kit&lt;/strong&gt; provides a machine learning–based alternative.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;But today, we’ll focus on &lt;strong&gt;ZXing.Net.MAUI&lt;/strong&gt;, one of the most popular and developer-friendly options.&lt;/p&gt;

&lt;p&gt;In this guide, you’ll learn &lt;strong&gt;everything you need&lt;/strong&gt; to integrate &lt;strong&gt;ZXing QR Code Scanner&lt;/strong&gt; in .NET MAUI — including installation, initialization, permissions, and a working example with XAML and C# code.&lt;br&gt;
We’ll also cover &lt;strong&gt;useful options&lt;/strong&gt; like torch and scan area, &lt;strong&gt;common issues&lt;/strong&gt;, and testing tips.&lt;/p&gt;

&lt;p&gt;🧩 &lt;strong&gt;Why Choose ZXing for .NET MAUI?&lt;/strong&gt;&lt;br&gt;
There are plenty of reasons developers prefer ZXing.Net.MAUI when adding barcode or QR code scanning features to their apps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Open-source and widely used&lt;/strong&gt; — trusted by many developers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Supports multiple barcode types&lt;/strong&gt; — QR, EAN, Code128, PDF417, and more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Works across platforms&lt;/strong&gt; — Android, iOS, and Windows (WinUI).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Includes both live camera scanning and image decoding.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easy to integrate and customize&lt;/strong&gt; — choose barcode formats, enable torch, or adjust detection options.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Actively maintained and community&lt;/strong&gt;-supported, ensuring stability and updates.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;⚙️ 1. &lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;br&gt;
Before diving in, make sure you have the following ready:&lt;/p&gt;

&lt;p&gt;✅ The latest &lt;strong&gt;.NET SDK *&lt;em&gt;(recommended *&lt;/em&gt;.NET 8&lt;/strong&gt;)&lt;br&gt;
✅ &lt;strong&gt;Visual Studio 2022&lt;/strong&gt; or later with the Mobile development with .NET workload installed&lt;br&gt;
✅ A working &lt;strong&gt;.NET MAUI project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you’re new to MAUI, open Visual Studio → Create New Project → choose .NET MAUI App.&lt;/p&gt;

&lt;p&gt;📦 2.&lt;strong&gt;Installation&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Step 1: Install the ZXing.Net.MAUI NuGet Package&lt;/strong&gt;&lt;br&gt;
Think of a NuGet package as a toolbox that adds new features to your app.&lt;br&gt;
To enable QR scanning, install the ZXing.Net.Maui.Controls package.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option 1 — Using CLI:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet add package ZXing.Net.Maui.Controls --version 0.4.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Option 2 — Using Visual Studio:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Right-click on your &lt;strong&gt;.NET MAUI project&lt;/strong&gt; in Solution Explorer.&lt;/li&gt;
&lt;li&gt;Select Manage &lt;strong&gt;NuGet Packages&lt;/strong&gt;…&lt;/li&gt;
&lt;li&gt;Go to the &lt;strong&gt;Browse&lt;/strong&gt; tab and search for &lt;strong&gt;ZXing.Net.Maui.Controls&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Install&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;This gives you access to ready-to-use UI controls such as the camera scanner view.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Initialize ZXing in MauiProgram.cs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your MAUI app needs to know that ZXing is part of the project. You do this by registering the barcode reader service in MauiProgram.cs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
using ZXing.Net.Maui;
public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp&amp;lt;App&amp;gt;()
            .UseBarcodeReader(); // register ZXing
        return builder.Build();
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡 Note: Depending on the package version, you may need to use&lt;br&gt;
.UseZXingNetMaui() instead of .UseBarcodeReader().&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Add Camera Permissions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Since scanning requires camera access, your app must request permissions or it’ll show a black screen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔹 Android&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Edit Platforms/Android/AndroidManifest.xml:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;uses-permission android:name="android.permission.CAMERA" /&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Android 6.0 (API 23) and above, request permission at &lt;strong&gt;runtime&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var status = await Permissions.RequestAsync&amp;lt;Permissions.Camera&amp;gt;();
if (status != PermissionStatus.Granted)
{
    // Handle permission denied
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🔹 iOS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open Platforms/iOS/Info.plist and add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;key&amp;gt;NSCameraUsageDescription&amp;lt;/key&amp;gt;
&amp;lt;string&amp;gt;This app uses the camera to scan QR codes.&amp;lt;/string&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you plan to scan images from the gallery, also add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;key&amp;gt;NSPhotoLibraryUsageDescription&amp;lt;/key&amp;gt;
&amp;lt;string&amp;gt;This app accesses your photo library to scan QR codes from images.&amp;lt;/string&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🔹 Windows (WinUI)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Edit &lt;code&gt;Package.appxmanifest&lt;/code&gt; and enable Webcam under Capabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🎥 3. Create the Scanner UI in XAML&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now let’s design the UI. ZXing provides a CameraBarcodeReaderView control for real-time scanning.&lt;/p&gt;

&lt;p&gt;Open your XAML page (e.g., ScannerPage.xaml) and add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8" ?&amp;gt;
&amp;lt;ContentPage
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:zxing="clr-namespace:ZXing.Net.Maui;assembly=ZXing.Net.MAUI"
    x:Class="MyMauiApp.Pages.ScannerPage"&amp;gt;
&amp;lt;Grid RowDefinitions="*,Auto" Padding="10"&amp;gt;
        &amp;lt;!-- Camera scanner view --&amp;gt;
        &amp;lt;zxing:CameraBarcodeReaderView 
                        x:Name="cameraView"
                        BarcodesDetected="CameraView_BarcodeDetected"
                        IsScanning="True"
                        IsTorchOn="False"
                        IsDetecting="True"
                        VerticalOptions="FillAndExpand" 
                  /&amp;gt;
        &amp;lt;!-- Result Label --&amp;gt;
            &amp;lt;StackLayout Grid.Row="1" 
             Orientation="Horizontal" 
              HorizontalOptions="Center"&amp;gt;
            &amp;lt;Label x:Name="ResultLabel"
            Text="No code scanned yet" 
            VerticalOptions="Center" /&amp;gt;
        &amp;lt;/StackLayout&amp;gt;
    &amp;lt;/Grid&amp;gt;
&amp;lt;/ContentPage&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;x:Name="cameraView" → gives a name to access it in C#.&lt;/li&gt;
&lt;li&gt;IsDetecting="True" → enables live scanning.&lt;/li&gt;
&lt;li&gt;BarcodesDetected="CameraView_BarcodeDetected" → triggers when a QR code is found.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;💻 4. Handle Scanned Results in Code-Behind&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Open the code-behind file (ScannerPage.xaml.cs) and implement your scan logic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using ZXing.Net.Maui;
using ZXing.Net.Maui.Controls;
public partial class ScannerPage : ContentPage
{
    bool _isProcessing = false;
    public ScannerPage()
    {
        InitializeComponent();
    }
    private void CameraView_BarcodeDetected(object sender, BarcodeDetectionEventArgs e)
    {
        var result = e.Results?.FirstOrDefault();
        if (result == null) return;
        if (_isProcessing) return;
        _isProcessing = true;
        MainThread.BeginInvokeOnMainThread(async () =&amp;gt;
        {
            cameraView.IsDetecting = false;
            ResultLabel.Text = result.Value ?? "Empty";
            await DisplayAlert("Scanned", result.Value, "OK");
            // Resume scanning if needed
            cameraView.IsDetecting = true;
            _isProcessing = false;
        });
    }
    protected override void OnDisappearing()
    {
        base.OnDisappearing();
        cameraView.IsDetecting = false;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🛠️ 5. Common Problems &amp;amp; Fixes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Black Screen or Blank Preview&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Usually caused by missing camera permission.&lt;/li&gt;
&lt;li&gt;Always check and request permissions at runtime.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;No Barcode Detected&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check lighting conditions or camera focus.&lt;/li&gt;
&lt;li&gt;Move the device closer to the QR code.&lt;/li&gt;
&lt;li&gt;Ensure IsDetecting="True" is set.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;⚡ Optimize Scanning Performance&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Restrict formats for faster detection:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cameraView.Options = new BarcodeReaderOptions {   
  Formats = BarcodeFormats.QrCode // or BarcodeFormats.All 
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.Use TryHarder = true for difficult lighting conditions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🧠 Final Thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That’s it! You’ve now integrated a &lt;strong&gt;fully functional QR Code Scanner in .NET MAUI using ZXing.Net.MAUI&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;ZXing is &lt;strong&gt;open-source, cross-platform, and easy to set up&lt;/strong&gt;, making it an excellent choice for most use cases. With just a few steps — installing the package, setting up permissions, and adding the XAML and C# logic — your MAUI app can now read QR codes and barcodes in real time.&lt;/p&gt;

&lt;p&gt;Whether you’re building a kiosk, attendance app, or mobile tool, ZXing.Net.MAUI gives you the flexibility and reliability you need.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>programming</category>
      <category>computerscience</category>
      <category>mobile</category>
    </item>
  </channel>
</rss>
