<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by yunho lee on Medium]]></title>
        <description><![CDATA[Stories by yunho lee on Medium]]></description>
        <link>https://medium.com/@lsy026302?source=rss-8f6a5142a0f8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*RtKApKxxPU2uqdj1gY6CyA.jpeg</url>
            <title>Stories by yunho lee on Medium</title>
            <link>https://medium.com/@lsy026302?source=rss-8f6a5142a0f8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 22:33:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lsy026302/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why Your ViewModel Is Technically Unstable — and Why Compose Doesn’t Mind]]></title>
            <link>https://proandroiddev.com/why-your-viewmodel-is-technically-unstable-and-why-compose-doesnt-mind-6b837ca4ce53?source=rss-8f6a5142a0f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b837ca4ce53</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[yunho lee]]></dc:creator>
            <pubDate>Wed, 05 Nov 2025 09:32:01 GMT</pubDate>
            <atom:updated>2025-11-10T02:26:45.756Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Why Your ViewModel Is Technically Unstable — and Why Compose Doesn’t Mind</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ztH8eZCwkLNq0eQtiKOn3w.png" /><figcaption>ai generated image</figcaption></figure><p>Did you know that almost all ViewModels are unstable?</p><p>When we first learn Compose,<br>we’re taught to use a stable class rather than an unstable class.</p><p>But ViewModels are unstable.<br>So why is it that no one says anything when we use unstable ViewModels?</p><h3>How does Compose determine stability?</h3><p>It is necessary to understand how the Compose compiler determines stability.</p><p>A class is considered stable if all its members are immutable or<br>types that are traceable by the Compose runtime.</p><pre>data class Stable(<br>    val a: Int, // Stable<br>    val b: MutableState&lt;Int&gt;, // Stable, Traceable in the Compose runtime<br>    val c: SnapshotStateList&lt;Int&gt; // Stable, Traceable in the Compose runtime<br>)<br><br>data class Unstable(<br>    var b: Int // Unstable<br>)<br><br>data class Runtime(<br>    val i: Interface // Uncertain, compose compiler don&#39;t know which implementation will be used at runtime.<br>)<br><br>interface Interface {<br>    data object Impl : Interface<br>}</pre><p>We can expect the compiler to determine stability as follows.</p><pre>stable class Stable {<br>  stable val a: Int<br>  stable val b: MutableState&lt;Int&gt;<br>  stable val c: SnapshotStateList&lt;Int&gt;<br>  &lt;runtime stability&gt; = Stable<br>}<br>unstable class Unstable {<br>  stable var b: Int<br>  &lt;runtime stability&gt; = Unstable<br>}<br>runtime class Runtime {<br>  runtime val i: Interface<br>  &lt;runtime stability&gt; = Uncertain(Interface)<br>}</pre><p>However, <strong>this determination applies only within the module where the Compose compiler plugin is declared</strong>.</p><h3><strong>When Stability Crosses Module Boundaries</strong></h3><p>I will demonstrate an example of creating a stable model in the Data Layer and injecting it into the ViewModel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*2hk9inWUBArS5FdWqe4kxg.png" /><figcaption>stableModel in data layer</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ZyFWAZ5iclDMmp7FVcpnw.png" /><figcaption>viewModel in presentation layer</figcaption></figure><p>If you’ve injected a generally stable class,<br>you would naturally expect the ViewModel to be stable as well.</p><p>However, the result is as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ydc2YMxB04eajAeuxXpoQw.png" /><figcaption>result</figcaption></figure><p>In this way, we can see that classes receiving injections from other layers also become unstable.</p><h3><strong>Why Unstable ViewModels Are Okay in Compose</strong></h3><p>A ViewModel typically injects a Repository or UseCase and acts as the connection point between the UI and business logic.</p><pre>class ViewModel(<br>    private val repository: Repository, // from domain or data layer<br>    private val useCase: UseCase // from domain layer<br>) : ViewModel()</pre><p>As we saw earlier, classes that inject classes from other layers are unstable.</p><p>Therefore, the ViewModel should also be an unstable class.</p><p>Yet we still wonder:<br>If the ViewModel is unstable, why is it acceptable?</p><h4>Answer</h4><p>The reason is simple.<br>We don’t pass the ViewModel itself to the composable we pass the stable state within the ViewModel.</p><pre>data class TestState(<br>    val data: String<br>)<br><br>@Composable<br>fun Screen(<br>    viewModel: TestViewModel<br>) {<br>    val state by viewModel.state.collectAsState()<br><br>    Child(state)<br>}<br><br>@Composable<br>fun Child(<br>    state: TestState<br>) {<br>    Text(state.data)<br>}</pre><p>A ViewModel is typically created only once in the top-level composable and passed as an argument. After that, it collects the state it manages and passes it down to child composables. Therefore, even if the ViewModel is unstable, it doesn’t actually cause problems.</p><h3>In Closing</h3><p>For monolithic projects, this isn’t a major issue.<br>Since all code compiles within a single module, stability assessments are straightforward.</p><p>However, if you’re considering a multi-module architecture and interested in Compose’s stability concepts,<br>this article will definitely be helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b837ca4ce53" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/why-your-viewmodel-is-technically-unstable-and-why-compose-doesnt-mind-6b837ca4ce53">Why Your ViewModel Is Technically Unstable — and Why Compose Doesn’t Mind</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Eliminating Jank in Composables: 3 Practical Techniques for Smooth Jetpack Compose UI]]></title>
            <link>https://proandroiddev.com/eliminating-jank-in-composables-3-practical-techniques-for-smooth-jetpack-compose-ui-6c66d4f7c4f4?source=rss-8f6a5142a0f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c66d4f7c4f4</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[yunho lee]]></dc:creator>
            <pubDate>Mon, 20 Oct 2025 09:34:13 GMT</pubDate>
            <atom:updated>2025-10-25T16:41:51.443Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7HqAGqJg2S2yrIz9VEq1Ag.png" /><figcaption>ai generated image</figcaption></figure><p>We often make the mistake of performing heavy operations inside Composables.</p><p>However, a Composable is just a function that constructs the UI and runs on the MainThread.</p><p>This means that during a Composable’s execution, the entire process of constructing and rendering the UI tree occurs on the main thread.</p><p>But what happens if heavy operations run concurrently at this point?</p><p>The UI update fails to process in time, causing the screen to momentarily freeze or stutter.</p><p>This is called Jank.</p><h3>FrameTime</h3><p>The FPS(frames per second) varies by device, but Generally, Android operates at 60 FPS.</p><p>This means that 60 frames must be drawn within 1 second (1000ms),</p><p>so the time available to process one frame is as follows.</p><pre>1000 / 60 = 16.63ms</pre><p>In other words, UI updates must complete within 16.63ms for the screen to display smoothly.</p><p>Exceeding this time limit causes frames to pile up, resulting in noticeable stuttering.</p><h3>Jank Example</h3><p>Let’s look at the following code.</p><pre>@Composable<br>fun Test() {<br>    LazyColumn(<br>        modifier = Modifier<br>            .statusBarsPadding()<br>            .height(300.dp)<br>            .fillMaxWidth()<br>    ) {<br>        item {<br>            Text(<br>                text = &quot;Janky Ui&quot;,<br>                fontSize = 32.sp<br>            )<br>        }<br><br>        items(100) {<br>            Text(computeHeavy(it))<br>        }<br>    }<br>}<br><br>fun computeHeavy(value: Int): String {<br>    Thread.sleep(100)<br><br>    return &quot;$value computed!&quot;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*-yqqiebwaAZZPdXNQ_vAbw.gif" /><figcaption>run on emulator</figcaption></figure><p>Each time a LazyColumn item is drawn, computeHeavy() is called,<br>causing the UI update to completely halt while this function runs on the main thread.<br>100ms far exceeds the frame time of 16.63ms,<br>resulting in multiple frames being pushed back and severe screen stuttering (Jank).</p><p>In other words, the UI still attempts to draw at 60FPS,<br>but the main thread is too busy with computation to secure drawing time.</p><p>So how should heavy tasks be handled to avoid Jank?</p><p>Here are 3 ways to handle this within the Compose environment.</p><h3>Handled in the ViewModel and displayed only in the UI</h3><p>Personally, I would choose this method first.</p><p>Heavy tasks are handled asynchronously in the ViewModel, and the UI simply displays the results, resulting in clean code and clear responsibilities.</p><pre>class TestViewModel : ViewModel() {<br>    private val _computed = MutableStateFlow&lt;List&lt;String&gt;&gt;(emptyList())<br>    val computed = _computed.asStateFlow()<br><br>    init {<br>        viewModelScope.launch {<br>            println(&quot;launch: ${Thread.currentThread().name}&quot;)<br>            withContext(Dispatchers.IO) {<br>                val results = (0 until 100).map {<br>                    async {<br>                        println(&quot;Async: ${Thread.currentThread().name}&quot;)<br>                        computeHeavy(it)<br>                    }<br>                }.awaitAll()<br><br>                _computed.update { results }<br>            }<br>        }<br>    }<br>}<br><br>@Composable<br>fun Test(viewModel: TestViewModel) {<br>    val computed by viewModel.computed.collectAsState()<br><br>    LazyColumn(<br>        modifier = Modifier<br>            .statusBarsPadding()<br>            .height(300.dp)<br>            .fillMaxWidth()<br>    ) {<br>        item {<br>            Text(<br>                text = &quot;viewModel&quot;,<br>                fontSize = 32.sp<br>            )<br>        }<br><br>        items(computed) {<br>            Text(it)<br>        }<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*d4buHWXVJVreV2ZkIir9vQ.gif" /><figcaption>run on emulator</figcaption></figure><p>An important point to note is that viewModelScope uses Dispatchers.Main.immediate by default. This means that unless you explicitly specify a different dispatcher, all coroutines started within it will run on the main thread.</p><p>Therefore, you must explicitly switch heavy tasks to Dispatchers.IO or Dispatchers.Default to avoid running them on the MainThread and prevent jank.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*s1YixWqQXNGs0Fhf0QHgag.png" /><figcaption>When context switching is not performed with WithContext</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cSBPVaATe3MlLPKRkwsVeg.png" /><figcaption>When context switching is performed using WithContext</figcaption></figure><h3>Handle asynchronously via ProduceState</h3><p>ProduceState, which fetches state asynchronously, can be an effective solution.</p><pre>@Composable<br>fun Test() {<br>    val computed by produceState(emptyList()) {<br>        value = withContext(Dispatchers.IO) {<br>            (0 until 100).map {<br>                async { computeHeavy(it) }<br>            }.awaitAll()<br>        }<br>    }<br><br>    LazyColumn(<br>        modifier = Modifier<br>            .statusBarsPadding()<br>            .height(300.dp)<br>            .fillMaxWidth()<br>    ) {<br>        item {<br>            Text(<br>                text = &quot;produceState&quot;,<br>                fontSize = 32.sp<br>            )<br>        }<br><br>        items(computed) {<br>            Text(it)<br>        }<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*MUgi-Lq18f90PkcLakXwAA.gif" /><figcaption>run on emulator</figcaption></figure><p>Within produceState, you can use suspend to initialize asynchronously,<br>making it an effective approach.</p><p>In this case as well, make sure to switch the context with Dispatchers.IO or Dispatchers.Default.</p><h3>Handle asynchronously via LaunchedEffect</h3><p>Using LaunchedEffect to handle processing within the EffectHandler is also a valid approach.</p><pre>@Composable<br>fun Test() {<br>    val computed = remember { mutableStateListOf&lt;String&gt;() }<br><br>    LaunchedEffect(Unit) {<br>        val results = withContext(Dispatchers.IO) {<br>            (0 until 100).map {<br>                async { computeHeavy(it) }<br>            }.awaitAll()<br>        }<br><br>        computed.addAll(results)<br>    }<br><br>    LazyColumn(<br>        modifier = Modifier<br>            .statusBarsPadding()<br>            .height(300.dp)<br>            .fillMaxWidth()<br>    ) {<br>        item {<br>            Text(<br>                text = &quot;LaunchedEffect&quot;,<br>                fontSize = 32.sp<br>            )<br>        }<br><br>        items(computed) {<br>            Text(it)<br>        }<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*22dUgmAiZ3epmpdUyP1iUQ.gif" /><figcaption>run on emulator</figcaption></figure><p>LaunchedEffect must also switch contexts using Dispatchers.IO or Dispatchers.Default.</p><h3>ProduceState vs LaunchedEffect Which one should I use?</h3><p>produceState internally uses LaunchedEffect</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bf9sjenjwTMtl-EL_U_3JQ.png" /><figcaption>implementation of produceState</figcaption></figure><p>but as its name suggests, it is focused on producing state.</p><p>Think about it. Wouldn’t it feel awkward to imagine some Effect occurring every time state is initialized?</p><p>Therefore, If you <strong>simply need to initialize a state asynchronously</strong>, using <strong>produceState</strong> is appropriate.</p><p>On the other hand, if you need <strong>additional</strong> <strong>effects alongside initialization</strong>, using <strong>LaunchedEffect</strong> is preferable.</p><h3>In Closing</h3><p>There’s rarely a need to perform heavy tasks directly in the UI,<br>and most processing will be handled in the ViewModel.</p><p>However, if your schedule is tight or you lack experience with Compose,<br>you might end up handling a significant amount of work inside Composables to display it in the UI without realizing it.</p><p>If that time comes, I hope you’ll recall the solutions introduced here and find them somewhat helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c66d4f7c4f4" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/eliminating-jank-in-composables-3-practical-techniques-for-smooth-jetpack-compose-ui-6c66d4f7c4f4">Eliminating Jank in Composables: 3 Practical Techniques for Smooth Jetpack Compose UI</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reducing Unnecessary Recompositions: 3 Practical Optimization Techniques for Jetpack Compose]]></title>
            <link>https://proandroiddev.com/recomposition-all-in-one-5bd1f4aedf8b?source=rss-8f6a5142a0f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bd1f4aedf8b</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[yunho lee]]></dc:creator>
            <pubDate>Wed, 24 Sep 2025 06:01:14 GMT</pubDate>
            <atom:updated>2025-10-14T05:48:43.196Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OBmuH5eKIZDrV3qKxGSS8Q.png" /><figcaption>ai generated image</figcaption></figure><p>Jetpack Compose is a declarative UI, so it follows the flow of state change → recomposition → UI update.</p><p>However, mishandling state can cause unnecessary recompositions, which directly leads to performance degradation.</p><p>This article compares techniques for reducing recompositions using Wrong examples and Correct examples.</p><h3>How to read the state within the narrowest possible range</h3><p><a href="https://developer.android.com/develop/ui/compose/performance/bestpractices#defer-reads">Reference From Android Developer</a></p><h4>Wrong</h4><pre>@Composable<br>private fun Parent() {<br>    var count by remember { mutableIntStateOf(0) }<br>    // Parent reads state directly → Parent undergoes full recomposition<br>    ChildA(count = count)<br>}<br><br>@Composable<br>private fun ChildA(count: Int) {<br>    Text(&quot;Count: $count&quot;)<br>}</pre><p>In Jetpack Compose, we often declare state using `by`.<br>The `by` keyword signifies property delegation, meaning it delegates access to the `value` of the State object.<br>In other words, simply referencing the variable internally calls `state.value`.</p><p>Compose tracks these `value` reads and automatically recomposes the composable that read the value when the state changes.<br>Therefore, if you’re passing a state down to a child without the parent composable directly using it,<br>you must structure the parent so it doesn’t “read” that state.<br>Otherwise, every composable inside the parent could be exposed to unnecessary recomposition.</p><h4>Correct</h4><pre>@Composable<br>fun Parent() {<br>    val count = remember { mutableStateOf(0) }<br><br>    // Pass a lambda that reads the state<br>    ChildB(count = { count.value })<br>    // Pass without reading the state<br>    ChildC(count = count)<br>}<br><br>@Composable<br>fun ChildB(count: () -&gt; Int) {<br>    Text(&quot;Count: ${count()}&quot;) // Here, the state is actually read.<br>}<br><br>@Composable<br>fun ChildC(count: State&lt;Int&gt;) {<br>    Text(&quot;Count: ${count.value}&quot;) // Here, the state is actually read.<br>}</pre><p>There are two ways to avoid this issue.<br>First, pass the State&lt;T&gt; object itself to the child instead of reading the state directly. If the parent does not call `state.value`, the parent is not traced as reading the state, and only when the child composable needs it does it read `state.value`, triggering a recomposition.</p><p>Second, pass the state access via a lambda. Since lambdas are functions (code, not values), any code inside the lambda that references `state.value` only executes when the lambda is actually called. This delays the state read to the point of invocation, ensuring it’s read only where it’s actually needed.</p><h4>Why is this method possible?</h4><p>Compose’s state is managed by the Snapshot System,<br>and all state read and write operations are tracked per snapshot.</p><p>The Snapshot System detects state changes<br>and informs the Compose Runtime that the composable (the scope of execution for a Composable function) that read that state must be re-executed.<br>In other words, snapshots serve to track triggers for recomposition caused by state changes.</p><p>For this tracking to be possible,<br>when state is read, the read operation must be registered in the global snapshot.<br>Through this process, Compose records “which composable read which state,”<br>enabling it to recompose only the appropriate scope later when that state changes.</p><pre>// Inside the mutableStateOf implementation<br>override var value: T<br>        get() = next.readable(this).value<br>        set(value) =<br>            next.withCurrent {<br>                if (!policy.equivalent(it.value, value)) {<br>                    next.overwritable(this, it) { this.value = value }<br>                }<br>            }</pre><p>You will see the value in this code. This value is the `state.value` we are using.</p><p>Let’s take a closer look at the getter.</p><pre>public fun &lt;T : StateRecord&gt; T.readable(state: StateObject): T {<br>    val snapshot = Snapshot.current<br>    // This is where the snapshot system indicates that the state has been read.<br>    snapshot.readObserver?.invoke(state)<br>    return readable(this, snapshot.snapshotId, snapshot.invalid)<br>        ?: sync {<br>            val syncSnapshot = Snapshot.current<br>            @Suppress(&quot;UNCHECKED_CAST&quot;)<br>            readable(state.firstStateRecord as T, syncSnapshot.snapshotId, syncSnapshot.invalid)<br>                ?: readError()<br>        }<br>}</pre><p>Calling `state.value` triggers the snapshot’s readObserver,<br>which informs the snapshot system where the state is being read from.</p><p>Through this process, Compose records “which composable read which state,”<br>and when that state changes, it can recompose only that specific part.</p><p>Therefore, to prevent unnecessary recompositions,<br>you should only read state at points where it is truly needed.<br>In other words, simply adjusting where state is read can effectively minimize the scope of recompositions.</p><h3>How to handle rapidly changing State</h3><h4>wrong</h4><pre>val showTopBar = lazyListState.firstVisibleItemIndex &gt; 20</pre><p>We sometimes derive one state from another.</p><p>If the state being used changes rapidly, like LazyListState, recompositions can occur quite frequently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*LkUYPsy2taYkX8433HbMJQ.png" /><figcaption>Android Studio also displays warnings directly.</figcaption></figure><h4>correct</h4><pre>// case of derivedStateOf<br>val showTopBar by remember {<br>    derivedStateOf { lazyListState.firstVisibleItemIndex &gt; 20 }<br>}<br><br>// case of snapshotFlow<br>var showTopBar by remember { mutableStateOf(false) }<br><br>LaunchedEffect(lazyListState) {<br>    snapshotFlow { lazyListState.firstVisibleItemIndex }<br>        .map { it &gt; 20 }<br>        .distinctUntilChanged()<br>        .collect { visible -&gt; showTopBar = visible }<br>}</pre><p>When dealing with rapidly changing states, you can use two methods.<br>The first is using derivedStateOf, and the second is using snapshotFlow.</p><p>Using derivedStateOf allows you to define a calculation block internally. When values change within that block, the state updates automatically.<br>In other words, the necessary calculation results are generated automatically based on state changes.</p><p>In contrast, snapshotFlow converts the state into a Flow, enabling us to process the data in the way we want.<br>Because we can define the calculation logic directly, we can flexibly implement various processing steps based on state changes.</p><h4>When should I use which method?</h4><p>When simply deriving state through calculations, it is recommended to use `derivedStateOf`.<br>However, when asynchronous processing is required alongside state changes, or when additional effects like toasts need to be triggered, using `snapshotFlow` is more appropriate.</p><p>In other words, if only the derived state is needed, choose `derivedStateOf` if you also need to handle side effects resulting from state changes, choose `snapshotFlow`.</p><h3>How to Defer state reads as long as possible</h3><h4>wrong</h4><pre>Text(<br>    modifier = Modifier<br>        .align(Alignment.Center)<br>        .offset(y = 60.dp * animatedValue)  // The state is read at the time of composition phase.<br>        .scale(animatedValue),              // The state is read at the time of composition phase.<br>    text = &quot;Animate&quot;<br>)</pre><p>We often use state and modifier to dynamically change a composable’s position, size, transparency, and so on.</p><p>However, if a rapidly changing state is read during the composition phase via modifier, unnecessary recomposition can occur frequently whenever that state changes abruptly.</p><h4>correct</h4><pre>Text(<br>    modifier = modifier<br>        .offset { IntOffset(0, (60 * animatedValue).toInt()) } // read state on layout phase<br>        .drawWithContent { // read state on draw phase<br>              scale(scale = animatedValue) {<br>                  this@drawWithContent.drawContent()<br>              }<br>         },<br>    text = &quot;Animate&quot;<br>)<br><br>// or<br><br>Text(<br>    modifier = modifier<br>        .offset { IntOffset(0, (60 * animatedValue).toInt()) } // read state on layoutphase<br>        .graphicsLayer { // read state on draw phase<br>            scaleX = animatedValue<br>            scaleY = animatedValue<br>        },<br>   text = &quot;Animate&quot;<br>)</pre><p>We can utilize methods that read state during the layout phase, like lambda Modifier,<br>or methods that read state during the draw phase, like `drawWithContent` or `graphicsLayer`.</p><h4>Why do we read the state after the Composition phase?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yknUCWShRkcHSupm9y5rtA.png" /><figcaption>from Android Developer Document</figcaption></figure><p>The process of rendering the UI on the screen in Compose consists of three main stages:<br>Composition, Layout, and Draw.</p><p>The key point to remember here is that during the Composition stage, if the state is read and changed, a recomposition occurs.</p><p>The Composition stage builds the UI Tree based on the state.<br>Once the UI Tree is constructed, the Layout stage arranges its components, and the Draw stage renders it on the screen.</p><p>Therefore, reading state during the Composition stage necessitates rebuilding the UI Tree whenever the state changes, triggering a recomposition.<br>Conversely, reading state during the Layout or Draw phases allows updating UI properties like position, size, or opacity without triggering a recomposition.</p><h3>In Closing</h3><p>Recomposition does not cause as significant a performance degradation as one might expect.<br>However, if you pay attention to recomposition,<br>you can eliminate at least one potential cause of future performance degradation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bd1f4aedf8b" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/recomposition-all-in-one-5bd1f4aedf8b">Reducing Unnecessary Recompositions: 3 Practical Optimization Techniques for Jetpack Compose</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Android Interview Questions Nobody Could Answer — Can You?]]></title>
            <link>https://proandroiddev.com/as-an-interviewer-i-asked-these-android-questions-can-you-answer-them-d623472568f7?source=rss-8f6a5142a0f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/d623472568f7</guid>
            <category><![CDATA[kotlin-coroutines]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[yunho lee]]></dc:creator>
            <pubDate>Wed, 17 Sep 2025 08:31:41 GMT</pubDate>
            <atom:updated>2025-09-28T14:16:39.867Z</atom:updated>
            <content:encoded><![CDATA[<h3><em>The Android Interview Questions Nobody Could Answer — Can You?</em></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kURRLiRHXcaIXdgorm7siQ.png" /><figcaption>ai generated image</figcaption></figure><p>As a 3 + year developer, I’ve participated as an interviewer in hiring interviews for team members.</p><p>At the time, I wanted to move beyond the typical quiz-style questions you often find on Google — those that can be answered with simple memorization.</p><p>Instead, I focused on crafting questions that would truly test a candidate’s depth of understanding.</p><p>Among the many I asked, there were three that no one managed to answer correctly. In this post, I’ll share those three with you. Can you answer them?</p><h3>Question 1</h3><p>What will be the order of the print statements in the code below? Also, could you explain why?</p><pre>// in Activity<br>override fun onCreate(savedInstanceState: Bundle?) {<br>    super.onCreate(savedInstanceState)<br>       <br>    lifecycleScope.launch {<br>        println(&quot;a&quot;)<br>    }<br>    <br>    GlobalScope.launch {<br>        println(&quot;b&quot;)<br>    }<br><br>    println(&quot;c&quot;)<br>}</pre><h4><strong>The answer I expected</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QWRUMDiFsCRkub9kYmA-0g.png" /><figcaption>actual execution</figcaption></figure><p>A C B</p><p><strong>Coroutines are often described as non-blocking</strong> <strong>because they actually operate without blocking threads.</strong> So even when you open a coroutine scope and execute it, <strong>it doesn’t block the main thread</strong>. Instead, the internal coroutine scheduler handles tasks asynchronously via the Dispatcher.</p><p>From this perspective, c might seem like it would run first. However, <strong>lifecycleScope uses Dispatchers.Main.immediate</strong> by default. <strong>This Dispatcher executes immediately if the current thread is the main thread</strong>, without dispatching separately.</p><p><strong>Consequently, a prints first</strong>.</p><p><strong>Next, c, which runs synchronously, prints.</strong></p><p><strong>Finally, b, which runs non-blockingly in a separate thread pool, prints.</strong></p><p>Therefore, the final order is <strong>a → c → b</strong>.</p><h4>Follow-up question</h4><p>Then, how can we make it print in the order a b c while maintaining the current coroutine scope?</p><h4>The answer I expected</h4><ul><li>Add Dispatcher.Unconfined or Dispatcher.Main.immediate to GlobalScope’s launch</li></ul><pre>GlobalScope.launch(Dispatchers.Main.immediate) { // or Dispatchers.Unconfined<br>    println(&quot;b&quot;)<br>}</pre><ul><li>Add CoroutineStart.UNDISPATCHED to GlobalScope’s launch</li></ul><pre>GlobalScope.launch(start = CoroutineStart.UNDISPATCHED) {<br>    println(&quot;b&quot;)<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5DGIxw8TX-R6qv5SQQFEQQ.png" /><figcaption>Both produce the same result as shown in the photo.</figcaption></figure><p>Dispatchers.Unconfined starts execution immediately on the <strong>current thread</strong>, while Dispatchers.Main.immediate starts immediately on the <strong>main thread</strong>. Since an Activity runs on the main thread, both dispatchers will begin execution right away in this context, which makes this approach valid.</p><p>Additionally, CoroutineStart.UNDISPATCHED is a start option for coroutine builders that allows the coroutine to begin execution immediately in the current call frame, before any suspension. This also ensures immediate execution on the current thread, so it is another valid way to achieve the desired order.</p><h4><strong>The intent of this question</strong></h4><p>This question tests your understanding of <strong>coroutines’ non-blocking behavior</strong> and your ability to distinguish and effectively use different <strong>Dispatchers</strong> and <strong>CoroutineScopes</strong></p><h3>Question 2</h3><p>Which of the following data classes would the Compose compiler consider Stable?</p><pre>data class A(val value: Int)<br><br>data class B(var value: Int)<br><br>data class C(val value: MutableState&lt;Int&gt;)<br><br>data class D(val value: List&lt;Int&gt;)<br><br>data class E(val value: SnapshotStateList&lt;Int&gt;)<br><br>data class F(val value: I)<br><br>sealed interface I {<br>    data object Child : I<br>}</pre><h4>The answer I expected</h4><p>A C E</p><p>In Compose, stability is determined based on whether the class’s internal properties are immutable or whether the Compose runtime can track the type.</p><ul><li><strong>A</strong>: <strong>Stable</strong> because its internal property is immutable.</li><li><strong>B</strong>: <strong>Unstable</strong> because its internal property is mutable and not traceable.</li><li><strong>C</strong>: <strong>Stable</strong> because its internal property is mutable but traceable by the Compose runtime.</li><li><strong>D</strong>: <strong>Unstable</strong> because List&lt;T&gt; is only a read-only API and does not guarantee immutability.</li><li><strong>E</strong>: <strong>Stable</strong> because it is a mutable list that is traceable by the Compose runtime.</li><li><strong>F</strong>: <strong>Runtime</strong> because the property is an interface type, its implementation is determined only at runtime, so stability cannot be resolved at compile time (<a href="https://android.googlesource.com/platform/frameworks/support/%2B/93a27bf544adcea26384f6612da46fef0275f631/compose/compiler/design/compiler-metrics.md#classes-classes_txt">reference</a>).</li></ul><p>So Answer is A C E</p><h4>Actual Compose Compiler Metrics</h4><pre>stable class A {<br>  stable val value: Int<br>  &lt;runtime stability&gt; = Stable<br>}<br>unstable class B {<br>  stable var value: Int<br>  &lt;runtime stability&gt; = Unstable<br>}<br>stable class C {<br>  stable val value: MutableState&lt;Int&gt;<br>  &lt;runtime stability&gt; = Stable<br>}<br>unstable class D {<br>  unstable val value: List&lt;Int&gt;<br>  &lt;runtime stability&gt; = Unstable<br>}<br>stable class E {<br>  stable val value: SnapshotStateList&lt;B&gt;<br>  &lt;runtime stability&gt; = Stable<br>}<br>runtime class F {<br>  runtime val value: I<br>  &lt;runtime stability&gt; = Uncertain(I)<br>}</pre><h4>The intent of this question</h4><p>This question tests your understanding of Compose’s stability rules and your ability to correctly identify and apply stable or unstable types.</p><h3>Question 3</h3><p>Select Child Composables that do not directly read the Count state from the Parent.</p><pre>@Composable<br>fun Parent() {<br>    val count = remember { mutableIntStateOf(0) }<br><br>    LaunchedEffect(Unit) {<br>        delay(1000)<br>        <br>        count.value += 1<br>    }<br><br>    ChildA(count.intValue)<br><br>    ChildB { count.intValue }<br><br>    ChildC(count)<br><br>    ChildD(count)<br>}<br><br>@Composable<br>fun ChildA(count: Int) {<br>    Text(&quot;$count&quot;)<br>}<br><br>@Composable<br>fun ChildB(count: () -&gt; Int) {<br>    Text(&quot;${count()}&quot;)<br>}<br><br>@Composable<br>fun ChildC(count: State&lt;Int&gt;) {<br>    Text(&quot;${count.value}&quot;)<br>}<br><br>@Composable<br>fun ChildD(count: State&lt;Int&gt;) {<br>    Text(&quot;$count&quot;)<br>} </pre><h4>The answer I expected</h4><p>B C D</p><p>In Compose, a state is considered read at the moment `value` is called. The Composable that reads that state is registered in the recomposition scope, triggering recomposition if that state changes.</p><ul><li>A: <strong>Reads state at Parent</strong>, Because `value` is Called in Parent Directly</li><li>B: <strong>Does not read state at Parent</strong>, Because a lambda is a function rather than a value, even if you call `value` inside the lambda, it is treated as if `value` were called at the point when the lambda itself executes.</li><li>C: <strong>Does not read state at Parent</strong>, Because the state’s `value` was passed without being called.</li><li>D: <strong>Does not read state at Parent</strong>, It’s for the same reason as C.</li></ul><p>So Answer is B C D</p><h4>Follow Up Question</h4><p>If the Count changes, will recomposition occur for ChildD? Or will it not occur?</p><h4>The answer I expected</h4><p>It does not occur. This is because ChildD was not registered in the recomposition scope since `value` was not called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*zTz8uD72-blktMKUODT2IQ.png" /><figcaption>A case where Child A, B, C, D are exist within Parent</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*lTVtp96UpRmhN2nM-bYiZQ.png" /><figcaption>A case where only Child B, C, D exist within Parent</figcaption></figure><p>When A is removed, it can be confirmed that Parent was excluded from the recomposition scope because it did not call `value`.</p><h4>The intent of this question</h4><p>This question tests your understanding of Jetpack Compose’s recomposition and your ability to control recomposition efficiently beyond just building UI.</p><h3>in Closing</h3><p>Did you find yourself unable to answer all the questions?</p><p>Don’t worry. In the actual interview, not a single person answered these questions perfectly.</p><p>If you’re only familiar with quiz-style questions, take this opportunity to learn that this type of interview question exists and prepare for it going forward. It will definitely be helpful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d623472568f7" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/as-an-interviewer-i-asked-these-android-questions-can-you-answer-them-d623472568f7">The Android Interview Questions Nobody Could Answer — Can You?</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automation Guide for Android Development: A Practical Step-by-Step Approach]]></title>
            <link>https://proandroiddev.com/android-development-teams-automation-journey-from-notion-api-to-mvi-component-creation-218a50647a45?source=rss-8f6a5142a0f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/218a50647a45</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[gradle-kotlin-dsl]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[yunho lee]]></dc:creator>
            <pubDate>Tue, 16 Sep 2025 02:57:35 GMT</pubDate>
            <atom:updated>2025-09-28T14:16:51.921Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lsy-n-eZ0aEclQfhWJ4qew.png" /><figcaption>ai generated image</figcaption></figure><p>When we talk about automation in Android, CI/CD often comes to mind.</p><p>However, automation isn’t limited to CI/CD; there are various automation methods developers can implement themselves.</p><p>This article introduces two such examples.</p><p>The most accessible approach for developers is leveraging Gradle.</p><p>Using <strong>Kotlin scripts</strong> is particularly recommended, as it allows for easy automation of simple repetitive tasks.</p><h3>How do I automate it?</h3><p>Automation via scripts can be approached through the following process:</p><ol><li>Identify recurring process rules</li><li>Verify required APIs for automation</li><li>Download RawData</li><li>Understand RawData structure</li><li>Extract necessary data</li><li>Generate output files</li></ol><p>Typically, automation follows these <strong>six steps</strong>.</p><p>However, if the automation simply involves creating files without external data sources, <strong>steps 2 through 5 can be omitted</strong>.</p><p>This blog post will explain <strong>automation using Notion and the automation of MVI component creation</strong> as examples.</p><h3>Automation Using the Notion DataSource API</h3><p>In this section, we will share a <strong>real-world case study</strong> demonstrating how we improved the repetitive and inefficient process of updating String Resources <strong>by leveraging the Notion API.</strong></p><h4>Background</h4><p>Previously, whenever a String Resource was updated, <strong>we distributed the resource via a Slack channel</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9o4wwMeC1V2MszYBpXF8yg.png" /><figcaption>Actual string resource deployment</figcaption></figure><p>Since distribution and application were handled manually by people, human errors frequently occurred.</p><p><strong><em>Developer A: Hey, the resources aren’t applied properly here, right?<br>Developer B: Did the planning team accidentally deploy the old resources as-is?<br>Developer C: Oh, sorry! I accidentally applied the previous version. T_T</em></strong></p><p>If everyone had always been fully alert, such mistakes wouldn’t have happened.</p><p>But ultimately, since both <strong>developers and planners are human, human error was bound to occur at any time.</strong></p><h4>Identifying Recurring Process Rules</h4><p>Before automating a process, you must first determine if it has consistency.</p><p>Without rules, even if you write a script, it will only result in limited automation that works only in specific situations.</p><p>Therefore, before attempting automation, <strong>you must always verify that the process has consistent rules.</strong></p><p><strong>In our company’s case</strong></p><p>Planner edit → Planner export → Slack channel deployment → Developer download → Developer import</p><p>While specific steps could vary depending on the situation, we were ultimately able to identify a consistent pattern within that framework.</p><h4>Identifying APIs Required for Automation</h4><p><em>Although we used the Ditto API during the actual automation implementation, for convenience in this article, we will refer to it as the Notion Database.</em></p><p>First, we need to <strong>examine where the planner is managing the String Resource.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r9AW459aiY8IfvKzLdVHhA.png" /><figcaption>This database is my personal Notion example for illustrative purposes.</figcaption></figure><p>In our company, planners were modifying and managing String Resources in the <strong>Notion Database</strong>.</p><p>What if developers could access this data programmatically?</p><p>It would allow reflecting the latest resources much more simply, without the existing deployment → download → import process.</p><p><a href="https://developers.notion.com/reference/query-a-data-source"><strong>Notion DataSource API</strong></a></p><p>In fact, the Notion DataSource API was well-documented, and the moment I confirmed this, I was able to take the first step toward automation.</p><h4>How to Use the Notion API</h4><p><em>In the previous version dated 2022–06–08, it was provided under the name Database API, but in the latest version dated 2025–09–03, it has been changed to DataSource API. The Database API is now deprecated, and we recommend using the DataSource API going forward. This post was written based on the 2025–09–03 version.</em></p><p>Before actually building automation, you first need to <strong>set up the Notion API.</strong></p><p>First, you must generate a <strong>Notion API Key</strong>.</p><p>Let’s generate a Notion API Key on the page below.</p><p><a href="https://www.notion.so/profile/integrations">The AI workspace that works for you. | Notion</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p0xK7XxBDb-SIHDoVnJzeQ.png" /></figure><p>First, click New Integration on my Integrations page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yCY7ZOWXVRHMS3pdLb42zQ.png" /></figure><p>Specify the API Key name and click Save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MBKDV_27bRHIZwy2QgeWwg.png" /></figure><p>You can now see the created Integration.</p><p>Now you’ll need to get the API Key, right? Click on the Integration you created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vfdAifZ-vLpOZpmjljQjXw.png" /></figure><p>Click the Show button in the Internal Integration Secret section to view your Notion API Key.</p><p>Save this key for later use when calling the API.</p><p>Note that the Notion API Key starts with <strong>ntn_</strong>.</p><p>Now, let’s <strong>connect the issued API Key to the Database</strong>.</p><p>If you skip this step, when calling the Notion API, you will receive an HTTP Code 404 along with a JSON response like the one below.</p><pre>{<br>  &quot;object&quot;: &quot;error&quot;,<br>  &quot;status&quot;: 404,<br>  &quot;code&quot;: &quot;object_not_found&quot;,<br>  &quot;message&quot;: &quot;Could not find database with ID: {your_datasource_id}. Make sure the relevant pages and databases are shared with your integration.&quot;,<br>  &quot;request_id&quot;: &quot;d6a2d15e-fefa-4f49-a1df-3b247fe96798&quot;<br>}</pre><p>The message indicates that the database for the specified ID cannot be found,<br>and instructs you to verify whether the page/database is shared with the integration permission.</p><p>In other words, the database must be shared with the integration for the API to function properly.</p><p>We will now connect the integration to the Notion page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2NvJqnnGwhiNxHuN5m_lOA.png" /></figure><p>First, navigate to the <strong>Notion page containing the String Board</strong>.</p><p>Then, click <strong>Settings &gt; Connections</strong> in the top menu,</p><p>and <strong>select the</strong> <strong>Integration you created earlier</strong> to complete the connection.</p><p>The <strong>next step is to obtain the DataSource ID</strong> for calling the Notion DataSource API.</p><p>This ID is required to actually retrieve the String Board data via the API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*1I_bqXeb_LTRKzXVSsIfiw.png" /></figure><p>Database Settings &gt; Manage Data Sources &gt; String Board Settings &gt; Copy Data Source ID</p><p>Follow the steps above to copy the Data Source ID.</p><p>All preparations for using the API are now complete.</p><p>With the preliminary work finished, we can now proceed to implement the automation.</p><h4>Download RawData</h4><p>Let’s include the DataSource ID and Notion API Key we prepared earlier in the HTTP Request Header.</p><pre>import java.net.http.HttpClient<br>import java.net.http.HttpRequest<br>import java.net.http.HttpResponse<br><br>private val httpClient = HttpClient.newHttpClient()<br><br>val request = HttpRequest.newBuilder()<br>            .uri(URI.create(&quot;https://api.notion.com/v1/data_sources/${dataSourceId}/query&quot;))<br>            .header(&quot;Authorization&quot;, notionApiKey)<br>            .header(&quot;Notion-Version&quot;, NOTION_VERSION)<br>            .header(&quot;Content-Type&quot;, &quot;application/json&quot;)<br>            .POST(HttpRequest.BodyPublishers.ofString(notionQuery))<br>            .build()<br>            <br> val response = httpClient.send(request, HttpResponse.BodyHandlers.ofString())<br> <br> val rawData = response.body() // The data we want</pre><p>We’ve now called the API targeting the String Board managed by the planner to retrieve the raw data!</p><p><em>If you include the Database ID directly in the Header as in the older version (2022–06–28), a 404 error will occur when calling the API.</em></p><p><em>In the latest version, you must use the DataSource ID. Please be careful not to confuse these two.</em></p><h4>Understand RawData structure</h4><p>Shall we take a look at the data we brought?</p><p><a href="https://wealthy-client-873.notion.site/Response-26f8bc2ec9148067b0ddf59db1dc17d5">Original Response</a></p><pre>{<br>  &quot;object&quot;: &quot;list&quot;,<br>  &quot;results&quot;: [<br>    {<br>      &quot;object&quot;: &quot;page&quot;,<br>      &quot;id&quot;: &quot;2648bc2e-c914-8081-b590-cd34eb4abbc6&quot;,<br>      &quot;created_time&quot;: &quot;2025-09-04T07:56:00.000Z&quot;,<br>      &quot;last_edited_time&quot;: &quot;2025-09-14T08:45:00.000Z&quot;,<br>      &quot;created_by&quot;: {<br>        &quot;object&quot;: &quot;user&quot;,<br>        &quot;id&quot;: &quot;b5f77005-4a06-41a4-a801-73fcc00f1b6b&quot;<br>      },<br>      &quot;last_edited_by&quot;: {<br>        &quot;object&quot;: &quot;user&quot;,<br>        &quot;id&quot;: &quot;b5f77005-4a06-41a4-a801-73fcc00f1b6b&quot;<br>      },<br>      &quot;cover&quot;: null,<br>      &quot;icon&quot;: null,<br>      &quot;parent&quot;: {<br>        &quot;type&quot;: &quot;data_source_id&quot;,<br>        &quot;data_source_id&quot;: &quot;25b8bc2e-c914-8072-bb67-000b5dffbb9b&quot;,<br>        &quot;database_id&quot;: &quot;25b8bc2e-c914-8051-ac4b-eb6b9aaf914a&quot;<br>      },<br>      &quot;archived&quot;: false,<br>      &quot;in_trash&quot;: false,<br>      &quot;is_locked&quot;: false,<br>      &quot;properties&quot;: {<br>        &quot;String: KOR&quot;: {<br>          &quot;id&quot;: &quot;%3CQz%7C&quot;,<br>          &quot;type&quot;: &quot;rich_text&quot;,<br>          &quot;rich_text&quot;: [<br>            {<br><br>... The rest is omitted.</pre><p>This is a complex JSON-formatted string…<br>But don’t panic — let’s calmly examine the data we need!</p><pre>{<br>  &quot;results&quot;: [<br>    {<br>      &quot;properties&quot;: {<br>        &quot;Resource ID&quot;: {<br>          &quot;title&quot;: [<br>            {<br>              &quot;plain_text&quot;: &quot;id-4&quot;<br>            }<br>          ]<br>        },<br>        &quot;String: KOR&quot;: {<br>          &quot;rich_text&quot;: [<br>            {<br>              &quot;plain_text&quot;: &quot;test&quot;<br>            }<br>          ]<br>        },<br>        &quot;String: ENG&quot;: {<br>          &quot;rich_text&quot;: [<br>            {<br>              &quot;plain_text&quot;: &quot;test&quot;<br>            }<br>          ]<br>        },<br>        &quot;String: JPN&quot;: {<br>          &quot;rich_text&quot;: [<br>            {<br>              &quot;plain_text&quot;: &quot;test&quot;<br>            }<br>          ]<br>        }<br>      }<br>    },<br>    <br>    ... other strings<br>  ]<br>}</pre><p>The response structure may appear complex, but it’s actually simple if you calmly examine only the values you need.</p><p>At the top level, there is a JsonArray named `results`, which contains multiple JsonObject elements.</p><p>Each JsonObject has a properties JsonObject, and within that, the values we need are Resource ID, String: KOR, String: BASE, and String: JPN.</p><p>In other words, without needing to examine the entire structure, simply following the path results → JsonObject → properties allows us to easily access the desired data.</p><p>Now that we understand the data structure, let’s go extract the values we want!</p><h4>Extract necessary data</h4><p>We will use Kotlin Serialization to parse JSON.</p><p>After converting the previously retrieved rawData into a JsonObject, we will extract only the necessary data according to the structure we have identified.</p><pre>import kotlinx.serialization.json.Json<br>import kotlinx.serialization.json.JsonArray<br>import kotlinx.serialization.json.JsonElement<br>import kotlinx.serialization.json.JsonObject<br>import kotlinx.serialization.json.jsonArray<br>import kotlinx.serialization.json.jsonObject<br>import kotlinx.serialization.json.jsonPrimitive<br><br>val json = Json.parseToJsonElement(rawData).jsonObject<br><br>// 1. Access results<br>val results = json[&quot;results&quot;]?.jsonArray ?: throw IllegalStateException(&quot;No results found&quot;)<br><br>// 2. Access the internal elements of results<br>val processedData = results.mapNotNull { element -&gt;<br>    // 3. Access properties<br>    val properties = element.jsonObject[&quot;properties&quot;]?.jsonObject ?: return@mapNotNull null<br><br>    // 4. Access the JSON we need inside the properties<br>    val idProperty = properties[&quot;Resource ID&quot;]?.jsonObject<br>    val resourceProperty = properties[&quot;String: KOR&quot;]?.jsonObject<br><br>    // 5. Extract text<br>    val resourceId = idProperty[&quot;title&quot;]?.jsonArray?.extractPlainText() ?: &quot;&quot;<br>    val resource = resourceProperty[&quot;rich_text&quot;]?.jsonArray?.extractPlainText() ?: &quot;&quot;<br><br>    // 6. process<br>    resourceId to resource<br>}<br><br>private fun JsonArray.extractPlainText(): String =<br>    joinToString(&quot;&quot;) { it.jsonObject[&quot;plain_text&quot;]?.jsonPrimitive?.content ?: &quot;&quot; }</pre><p>Following the structure we outlined earlier makes this straightforward.</p><p>results (JsonArray)<br>→ element (JsonObject)<br>→ properties (JsonObject)<br>→ Resource ID (JsonObject), String: KOR (JsonObject)<br>Accessing in this order and extracting plain_text yields the desired value (String).</p><p>The extracted value is packaged as a (resourceId, resource) pair for easier use.</p><p>In actual implementation, we need to extract Korean, English, and Japanese strings,</p><p>but here, we’ve simplified the code to extract only Korean (KOR).</p><h4>Generate output files</h4><p>Now we’re at the final step.</p><p>Let’s process the previously extracted data to match the Android String XML format we need.</p><pre>import java.io.File<br><br>val directory = File(outputDir, &quot;values&quot;).apply { mkdirs() }<br>val outputFile = File(directory, &quot;string.xml&quot;)<br><br>outputFile.bufferedWriter().use { writer -&gt;<br>    writer.appendLine(&quot;&quot;&quot;&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&quot;&quot;&quot;)<br>    writer.appendLine(&quot;&quot;&quot;&lt;resources xmlns:xliff=&quot;urn:oasis:names:tc:xliff:document:1.2&quot;&gt;&quot;&quot;&quot;)<br><br>    processedData.forEach { (resourceId, resource) -&gt;<br>          writer.appendLine(&quot;&quot;&quot;    &lt;string name=&quot;$resourceId&quot;&gt;$resource&lt;/string&gt;&quot;&quot;&quot;)<br>    }<br><br>    writer.appendLine(&quot;&quot;&quot;&lt;/resources&gt;&quot;&quot;&quot;)<br>}</pre><p><strong>The goal was to convert a Notion Database to Android String XML</strong>, right?</p><p>To do this, we first prepare the basic XML structure and then merge the extracted string data into it.</p><p>Specifically, we create the XML header and the &lt;resources&gt; tag, then convert each resourceId and resource into &lt;string&gt; tags and insert them to complete the process.</p><h4>Run</h4><p>This execution screen is not sample code, but rather the <a href="https://github.com/lyh990517/android-notion-string-plugin"><strong><em>Notion String Plugin</em></strong></a> I have released.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vO3jDOVImketA0PuTPSf4g.png" /></figure><p>Now, even if planners modify the String Board,<br>they can directly fetch it via API without going through the inefficient Slack deployment process anymore!</p><p><strong>Before</strong></p><p>Planner modification → Planner export → Slack channel deployment → Developer download → Developer import</p><p><strong>After</strong></p><p>Planner modification → Developer script execution</p><p>By eliminating unnecessary steps, the process has become much more streamlined.</p><p><em>The example code in this section has been simplified to focus solely on the core implementation of automation.</em></p><p><em>If you’d like to see the fully functional code in action, please refer to the </em><a href="https://github.com/lyh990517/android-notion-string-plugin"><strong><em>Notion String Plugin</em></strong></a><em> repository.</em></p><h3>automation of MVI component creation</h3><p>In this section, we will introduce a <strong>case study where we automated the creation of MVI components according to our team’s conventions</strong>.</p><h4>Background</h4><p>Below is the actual MVI structure used by the team.</p><pre>feature/src/main/kotlin/<br>└── {basePackage}/<br>    └── {featurePath}/<br>        ├── intent/<br>        │   ├── {FeatureName}State.kt<br>        │   ├── {FeatureName}Event.kt<br>        │   └── {FeatureName}SideEffect.kt<br>        └── view/<br>            ├── {FeatureName}.kt<br>            ├── model/<br>            │   └── {FeatureName}ViewModel.kt<br>            └── component/<br>                ├── {FeatureName}Dialog.kt<br>                └── {FeatureName}DialogState.kt</pre><p>When developing a single feature (screen), we had to organize directories and files as shown above according to convention.</p><p>Code also required repeatedly writing similar patterns.</p><p>Nowadays, AI tools like Firebender have advanced significantly. By injecting predefined rules, they automatically handle most repetitive tasks.</p><p>However, <strong>AI isn’t 100% accurate</strong>, so human review is still necessary. More than anything, <strong>having to wait 1–3 minutes for the task to complete</strong> was subtly frustrating…</p><h4>Identifying Recurring Process Rules</h4><p>Upon analysis, we determined that a total of seven components must be created when developing a single screen (feature).</p><ul><li>State</li><li>Event</li><li>SideEffect</li><li>Ui</li><li>ViewModel</li><li>Dialog</li><li>DialogState</li></ul><p><em>Although Dialog is not a component of MVI, it is included in the automation scope because it is present on nearly every screen.</em></p><p>Therefore, <strong>the goal is to automatically generate the above 7 files</strong> via script.</p><p>While the Notion-based automation covered earlier required processing external data sources,<br>this case simply involves defining a <strong>format aligned with team conventions and generating files accordingly</strong>.</p><p>In other words, without complex parsing or data cleansing processes,<br>merely generating files can efficiently reduce repetitive tasks.</p><p>Previously, when developing a feature named “Test,” code had to be generated as shown in the link below.</p><p><a href="https://www.notion.so/Feature-2708bc2ec9148041a9a4f72ad5d583bc"><strong><em>Sample</em></strong></a></p><p>Since these code snippets share the same structure across any feature,<br>templatizing the repetitive boilerplate code eliminates the need to write it each time.</p><h4>Generate output files</h4><p><em>The code is too extensive to handle all files at once, so we’ll first examine it based on creating a SideEffect file.</em></p><p>First, the code we need to write ourselves is as follows.</p><pre>package com.yunho.feature.test.intent<br><br>import com.yunho.feature.test.view.component.TestDialogState<br><br>sealed interface TestSideEffect {<br>    sealed interface Navigate : TestSideEffect {<br>        data object Back : Navigate<br>    }<br><br>    sealed interface Show : TestSideEffect {<br>        data class Dialog(val content: TestDialogState.Content) : Show<br>    }<br><br>    sealed interface Hide : TestSideEffect {<br>        data object Dialog : Hide<br>    }<br>}</pre><p>Two important facts can be gleaned here.</p><ul><li>Test → <strong>FeaturePath</strong></li><li>com.yunho.feature → <strong>BasePackage</strong></li></ul><p>In other words, the package name and class name of the files we need to generate<br>are determined based on two elements: <strong>BasePackage</strong> and <strong>FeaturePath</strong>.</p><p>Therefore, if <strong>we take these two as parameters in Gradle and inject them</strong>,<br>the remaining files can be automatically generated using the same principle.</p><p>In Gradle, you can pass parameters from the outside using the -P option as shown below.</p><pre>./gradlew -PfeaturePath=test -PbasePackage=com.yunho.feature generateMviTemplate</pre><p>And in the code, it is received as follows</p><pre>val featurePath = findProperty(&quot;featurePath&quot;)?.toString() ?: throw GradleException(&quot;❌ Please pass -PfeaturePath=FeatureName&quot;)<br>val basePackage = findProperty(&quot;basePackage&quot;)?.toString() ?: throw GradleException(&quot;❌ Please pass -PbasePackage=com.example.app&quot;)</pre><p>Now, using the <strong>featurePath</strong> and <strong>basePackage</strong> we’ve obtained,<br>let’s automatically generate the SideEffect file according to the convention.</p><pre>import org.gradle.api.Project<br>import java.io.File<br><br>val root = rootProject.file(&quot;feature/src/main/kotlin&quot;)<br>val basePath = basePackage.replace(&#39;.&#39;, &#39;/&#39;)<br>val featureDir = srcRoot.resolve(&quot;$basePath/$featurePath&quot;)<br>val featureName = featurePath.replaceFirstChar { it.uppercaseChar() }<br>val intentDir = featureDir.resolve(&quot;intent&quot;).apply { mkdir() }<br><br>File(<br>    intentDir,<br>    &quot;${featureName}SideEffect.kt&quot;<br>).writeText(<br>    &quot;&quot;&quot;<br>    package $basePackage.$featurePath.intent<br><br>    import $basePackage.$featurePath.view.component.${featureName}DialogState<br><br>    sealed interface ${featureName}SideEffect {<br>        sealed interface Navigate : ${featureName}SideEffect {<br>            data object Back : Navigate<br>        }<br><br>        sealed interface Show : ${featureName}SideEffect {<br>            data class Dialog(val content: ${featureName}DialogState.Content) : Show<br>        }<br><br>        sealed interface Hide : ${featureName}SideEffect {<br>            data object Dialog : Hide<br>        }<br>    }<br>    &quot;&quot;&quot;.trimIndent()<br>)</pre><p>We simply inject the <strong>featurePath</strong> and <strong>basePackage</strong> parameters we received,<br>and <strong>create a Text file following the code convention</strong>.</p><p>It’s really simple, isn’t it?</p><h4>Run</h4><p><em>This execution screen is not sample code but my GitHub repository for </em><a href="https://github.com/lyh990517/Android-Automated-MVI"><strong><em>Android-Automated-MVI</em></strong></a><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1bwlL8uCpdU3wPNg8mM-dQ.png" /></figure><p>No more writing code line by line.</p><p>From now on, even when you receive a new screen design document in Figma, you can skip the tedious setup process with just one click of the script<br>and immediately focus on core UI development.</p><p><em>The example code in this section has been simplified to focus solely on the core automation implementation.</em></p><p><em>If you’d like to see the fully functional code in action, please refer to the </em><a href="https://github.com/lyh990517/Android-Automated-MVI"><strong><em>Android-Automated-MVI</em></strong></a><em> repository.</em></p><h3>In closing</h3><p>Improving productivity often involves a theoretical approach: maintaining clean code and structure to facilitate scalability and bug fixes.</p><p>While this remains important, the fast-paced environment of a startup requires a different set of tools.</p><p>Automating repetitive, routine tasks allows developers to focus on solving more critical problems and enhancing the product.</p><p>These days, tools like Firebender or ChatGPT are so well-developed that anyone can easily build automation as long as the requirements are clear.</p><p>You don’t need to start with big things.</p><p>Why not try automating small tasks one by one?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=218a50647a45" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/android-development-teams-automation-journey-from-notion-api-to-mvi-component-creation-218a50647a45">Automation Guide for Android Development: A Practical Step-by-Step Approach</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>