Posts

🚀 Improve Your Android App Performance with StrictMode

Image
 Stop UI Jank and ANRs by Catching Main-Thread Violations Before They Reach Your Users. In the competitive world of Android development, a “buttery smooth” 60fps experience (and up to 120Hz on supported devices) is the baseline for user trust. But as codebases grow, “hidden” disk I/O or network calls can creep onto the Main Thread, leading to micro-stutters or the dreaded  ANR (App Not Responding)  dialog. 💡 Key Takeaway:  If it touches the disk or the network, it should  never  run on the main thread. 🚨  Rule:  The main thread is for UI only — nothing else. StrictMode  is your automated “code police.” It doesn’t just find bugs; it enforces architectural discipline by catching performance violations during development before they ever reach a user’s device. ⚙️ Modern Setup: The “Zero Tolerance” Configuration The best practice is to initialize StrictMode as early as possible — usually in your  Application  class—and  only ...

Why are Function Types Stable in Jetpack Compose?

Image
 Unpacking the "Observability Gap" and why () -> Unit is stable even when its data is not. Why does a lambda that returns unstable data still count as “stable” in Compose? The answer reveals how recomposition actually works under the hood. TL;DR:  In Jetpack Compose, function types (lambdas) are considered  stable  because their  identity  is the only observable signal Compose can use during recomposition. However, stability does not guarantee reactivity — state must be read inside composables, not hidden inside lambdas. To maintain performance, you must manually manage identity using  remember . The Mental Model: Compose Recomposition vs. Execution Phase To understand function stability, you must distinguish between the two distinct timings in a Composable’s lifecycle: Recomposition Phase:  Compose compares inputs to decide if it can skip a function. If inputs (like a lambda) have the same  identity , Compose  skips  the work. E...