Posts

Deep Links in Jetpack Compose: The Architectural Backbone You're Ignoring

Image
 Beyond "URL-to-Screen": Mastering Synthetic Backstacks, Cold Starts, and Auth-Gated Navigation. Most Android developers treat deep links as a “post-it note” feature: you stick a URL onto an Activity in the manifest, point it to a screen, and call it a day. In a production-grade Jetpack Compose app, deep links are not just “shortcuts” — they are  entry points that bypass your natural app flow.  If you don’t architect for them, you are essentially leaving a back door open that leads straight into a wall. Who This Article Is For This guide is specifically for Android developers who: Are using  Jetpack Compose Navigation  in production. Support deep links from  marketing emails, web redirects, or push notifications. Have experienced  broken back navigation  or  cold-start crashes. 1. Visualizing the Synthetic Backstack In Compose, a deep link doesn’t just open a screen; it triggers the construction of a  Synthetic Backstack . This stack is ...

Mastering ViewModel Unit Testing with Kotlin Flow & StateFlow

Image
 Beyond the basics: How to use Turbine, StandardTestDispatcher, and Structured Concurrency to write production-ready Android tests. TL;DR Inject Dispatchers:  Never hardcode them; use a  DispatcherProvider . Structured Concurrency:  Launch on  viewModelScope  without a dispatcher; use  withContext  for I/O. Safer Testing:  Prefer  StandardTestDispatcher  over  Unconfined  for realistic execution. Collect Early:  Always start your Turbine collection  before  triggering ViewModel actions. Hot Stream Nuance:  Remember that  StateFlow  immediately emits its current value upon collection. The Architecture of a Modern ViewModel To test a ViewModel effectively, we must separate the  threading policy  from the  business logic . By injecting a  DispatcherProvider , we gain the ability to "freeze" or "advance" time in our tests. The Optimized Pattern class ProductViewModel ( pri...