<?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 Abhijit Rajmane on Medium]]></title>
        <description><![CDATA[Stories by Abhijit Rajmane on Medium]]></description>
        <link>https://medium.com/@rajmane5151_23114?source=rss-6bc4fa104dfa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8_YlBd4HZqTjYsfLXfhL-w.png</url>
            <title>Stories by Abhijit Rajmane on Medium</title>
            <link>https://medium.com/@rajmane5151_23114?source=rss-6bc4fa104dfa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 23:51:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rajmane5151_23114/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[Kotlin Context Parameters: The Feature That’s Replacing Dependency Injection Boilerplate]]></title>
            <link>https://medium.com/@rajmane5151_23114/kotlin-context-parameters-the-feature-thats-replacing-dependency-injection-boilerplate-f793ffe39ccb?source=rss-6bc4fa104dfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/f793ffe39ccb</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Abhijit Rajmane]]></dc:creator>
            <pubDate>Fri, 07 Aug 2026 07:45:09 GMT</pubDate>
            <atom:updated>2026-08-07T07:45:09.576Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yP8H-B2fcQqLCEG0EyhCfg.png" /></figure><p>If you’ve written Kotlin for more than a year, you know this pain: a Logger, a Database, a UserSession, or some config object that has to be threaded through <em>every single function signature</em> in a call chain — even in functions that don&#39;t use it directly, just to hand it down to something deeper that does.</p><p>Kotlin 2.x’s <strong>context parameters</strong> (the production-ready evolution of the old “context receivers” experimental feature) fix this. They let you declare what a function <em>requires from its environment</em> without adding it as an explicit argument every caller has to remember to pass.</p><p>This tutorial walks through what changed, why it matters, and how to actually use it in real code.</p><h3>The problem: parameter drilling</h3><p>Say you’re building an order-processing pipeline. Every layer needs a logger and a database connection.</p><p>kotlin</p><pre>fun processOrder(order: Order, logger: Logger, db: Database) {<br>    logger.log(&quot;Processing order ${order.id}&quot;)<br>    validateOrder(order, logger, db)<br>}</pre><pre>fun validateOrder(order: Order, logger: Logger, db: Database) {<br>    logger.log(&quot;Validating order ${order.id}&quot;)<br>    checkInventory(order, logger, db)<br>}</pre><pre>fun checkInventory(order: Order, logger: Logger, db: Database) {<br>    logger.log(&quot;Checking inventory for ${order.id}&quot;)<br>    val stock = db.query(&quot;SELECT * FROM inventory WHERE id = ${order.id}&quot;)<br>    // ...<br>}</pre><p>Every function down the chain has to carry logger and db, whether it uses them directly or just passes them along. Add a third dependency later — say, a MetricsCollector — and you&#39;re editing every signature in the chain again. This is what people mean by &quot;parameter drilling,&quot; and it&#39;s the same problem React developers complain about with prop drilling before context/state management tools.</p><p>The usual fixes — a DI framework (Koin, Hilt, Dagger), a shared class holding dependencies, or a global singleton — all work, but they come with their own costs: runtime overhead, boilerplate annotations, testability trade-offs, or just “magic” that’s hard to trace.</p><h3>The fix: context parameters</h3><p>Context parameters let a function declare a dependency as part of its <em>context</em> rather than its explicit parameter list. Callers don’t pass it manually — it’s picked up implicitly from the calling scope, as long as something in that scope provides it.</p><p>Here’s the same pipeline rewritten:</p><p>kotlin</p><pre>context(logger: Logger, db: Database)<br>fun processOrder(order: Order) {<br>    logger.log(&quot;Processing order ${order.id}&quot;)<br>    validateOrder(order)<br>}</pre><pre>context(logger: Logger, db: Database)<br>fun validateOrder(order: Order) {<br>    logger.log(&quot;Validating order ${order.id}&quot;)<br>    checkInventory(order)<br>}</pre><pre>context(logger: Logger, db: Database)<br>fun checkInventory(order: Order) {<br>    logger.log(&quot;Checking inventory for ${order.id}&quot;)<br>    val stock = db.query(&quot;SELECT * FROM inventory WHERE id = ${order.id}&quot;)<br>    // ...<br>}</pre><p>At the call site, you provide the context once:</p><p>kotlin</p><pre>context(logger, db) {<br>    processOrder(myOrder)<br>}</pre><p>Everything inside that block — and everything those functions call — automatically has access to logger and db, without either being an explicit argument. Add metrics as a third dependency later, and you only touch the functions that actually use it, plus the top-level context declaration.</p><h3>A more realistic example: request-scoped auth</h3><p>Context parameters shine when a value is tied to a <em>scope</em> rather than passed data — like a signed-in user during a request.</p><p>kotlin</p><pre>data class CurrentUser(val id: String, val role: String)</pre><pre>context(user: CurrentUser)<br>fun requireAdmin() {<br>    check(user.role == &quot;ADMIN&quot;) { &quot;User ${user.id} is not authorized&quot; }<br>}</pre><pre>context(user: CurrentUser)<br>fun deletePost(postId: String) {<br>    requireAdmin()<br>    println(&quot;Post $postId deleted by ${user.id}&quot;)<br>}</pre><pre>fun handleDeleteRequest(postId: String, sessionUser: CurrentUser) {<br>    context(sessionUser) {<br>        deletePost(postId)<br>    }<br>}</pre><p>requireAdmin() doesn&#39;t need user passed to it explicitly — it&#39;s implicitly available anywhere inside a context(sessionUser) { ... } block, including in nested calls like deletePost. This reads closer to how you <em>think</em> about the problem: &quot;while handling this request, the current user is available&quot; — rather than manually plumbing it everywhere.</p><h3>When to reach for it (and when not to)</h3><p><strong>Good fits:</strong></p><ul><li>Cross-cutting concerns: logging, tracing, metrics</li><li>Request/session-scoped values (current user, transaction, locale)</li><li>Building small DSLs where implicit context makes the call site cleaner</li></ul><p><strong>Not a good fit:</strong></p><ul><li>Values that vary meaningfully per call — if two calls to the same function legitimately need different Database instances in the same scope, an explicit parameter is clearer</li><li>Public API surfaces used by teams unfamiliar with the feature — implicit context can hurt readability for newcomers if overused</li><li>As a wholesale replacement for DI frameworks in large multi-module apps — Koin/Hilt still handle object graph construction, lifecycle, and scoping in ways context parameters don’t attempt to replace</li></ul><h3>Gotchas</h3><ul><li><strong>IDE support is still catching up.</strong> Autocomplete and “find usages” for context parameters are less mature than for regular parameters in some IDE versions — double check your Android Studio / IntelliJ version.</li><li><strong>Overuse hides dependencies.</strong> The whole point is to reduce visible plumbing, but that’s a double-edged sword: a function’s true dependencies become less obvious just by reading its signature. Use it for genuinely cross-cutting concerns, not everything.</li><li><strong>Interop with pre-2.x Kotlin code</strong> requires care — context parameters don’t exist in older Kotlin, so shared libraries targeting multiple Kotlin versions need a fallback path.</li></ul><h3>Takeaway</h3><p>Context parameters aren’t a replacement for dependency injection frameworks — they solve a narrower, more common problem: passing cross-cutting values down a call chain without cluttering every signature. For loggers, tracing, request-scoped state, and small DSLs, they cut real boilerplate. For your app’s actual object graph, keep using Koin, Hilt, or manual DI — and reach for context parameters as a complementary tool, not a wholesale swap.</p><p>If you’re on Kotlin 2.x and haven’t tried this yet, it’s worth an afternoon experimenting with in a side project before bringing it into production code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f793ffe39ccb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding InheritedWidget vs Provider in Flutter (with Example)]]></title>
            <link>https://medium.com/@rajmane5151_23114/understanding-inheritedwidget-vs-provider-in-flutter-with-example-694edaece0a6?source=rss-6bc4fa104dfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/694edaece0a6</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[flutter-development]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Abhijit Rajmane]]></dc:creator>
            <pubDate>Wed, 15 Oct 2025 07:14:53 GMT</pubDate>
            <atom:updated>2025-10-15T07:14:53.257Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*3LFgJKoQqDTNeXv4ZGRRQQ.jpeg" /></figure><p>Flutter gives us several ways to <strong>share data</strong> down the widget tree from <strong>basic stateful widgets</strong> to <strong>advanced state management libraries</strong>.</p><p>Two important concepts to understand are:</p><ul><li>InheritedWidget — the <strong>foundation</strong> of Flutter’s context-based data sharing.</li><li>Provider — a <strong>simpler, higher-level abstraction</strong> built on top of InheritedWidget.</li></ul><p>In this article, we’ll explore both, build an example, and understand when to use each.</p><h3>What’s an InheritedWidget?</h3><p>When you build Flutter apps, sometimes you need to share data down the widget tree like theme data, user info, or counters.<br> Normally you’d pass it through constructors, but that gets messy really fast.</p><p>That’s where <strong>InheritedWidget</strong> comes in.<br> It helps you <strong>share data efficiently</strong> with all the widgets below it in the tree, <strong>without</strong> passing it manually each time.</p><h3>Let’s Build a Simple Example</h3><p>We’ll build a small app that shares a counter value across widgets using InheritedWidget.</p><h3>Step 1: Create the InheritedWidget</h3><pre>class CounterProvider extends InheritedWidget {<br>  final int counter;<br>  final VoidCallback increment;<br><br>  const CounterProvider({<br>    Key? key,<br>    required this.counter,<br>    required this.increment,<br>    required Widget child,<br>  }) : super(key: key, child: child);<br><br>  // to get the provider easily<br>  static CounterProvider? of(BuildContext context) {<br>    return context.dependOnInheritedWidgetOfExactType&lt;CounterProvider&gt;();<br>  }<br><br>  // tells Flutter when to rebuild<br>  @override<br>  bool updateShouldNotify(CounterProvider oldWidget) {<br>    return counter != oldWidget.counter;<br>  }<br>}</pre><p>So what’s happening here?</p><ul><li>We extend InheritedWidget.</li><li>We store our shared data (counter) and function (increment).</li><li>of() helps us easily access the widget from anywhere down the tree.</li><li>updateShouldNotify() tells Flutter when to rebuild widgets that depend on this data.</li></ul><h3>Step 2: Create the Root Widget with State</h3><pre>class MyApp extends StatefulWidget {<br>  @override<br>  State&lt;MyApp&gt; createState() =&gt; _MyAppState();<br>}<br><br>class _MyAppState extends State&lt;MyApp&gt; {<br>  int _counter = 0;<br><br>  void _increment() {<br>    setState(() {<br>      _counter++;<br>    });<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return CounterProvider(<br>      counter: _counter,<br>      increment: _increment,<br>      child: MaterialApp(<br>        home: CounterHome(),<br>      ),<br>    );<br>  }<br>}</pre><p>This widget manages the counter and wraps the rest of the app inside our CounterProvider.<br> That way, everything below can access the counter value.</p><h3>Step 3: Use the Data in a Child Widget</h3><pre>class CounterHome extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    final provider = CounterProvider.of(context)!;<br><br>    return Scaffold(<br>      appBar: AppBar(title: const Text(&#39;InheritedWidget Example&#39;)),<br>      body: Center(<br>        child: Text(<br>          &#39;Counter Value: ${provider.counter}&#39;,<br>          style: const TextStyle(fontSize: 24),<br>        ),<br>      ),<br>      floatingActionButton: FloatingActionButton(<br>        onPressed: provider.increment,<br>        child: const Icon(Icons.add),<br>      ),<br>    );<br>  }<br>}</pre><p>And that’s it!<br>Now every time we tap the button, the counter increases, and the UI updates automatically.</p><h3>Now Let’s See Provider</h3><p>While InheritedWidget works, you can see it’s a bit too much code just to share a counter.<br> That’s why we usually use the <strong>Provider</strong> package — it’s built on top of InheritedWidget but way simpler to use.</p><h3>Step 1: Add Provider Dependency</h3><p>In your pubspec.yaml, add this line:</p><pre>dependencies:<br>  provider: ^6.0.0</pre><p>Then run flutter pub get.</p><h3>Step 2: Create a Model Class</h3><pre>class CounterModel extends ChangeNotifier {<br>  int _count = 0;<br>  int get count =&gt; _count;<br><br>  void increment() {<br>    _count++;<br>    notifyListeners(); // tells widgets to rebuild<br>  }<br>}</pre><h3>Step 3: Wrap Your App</h3><pre>void main() {<br>  runApp(<br>    ChangeNotifierProvider(<br>      create: (_) =&gt; CounterModel(),<br>      child: const MyApp(),<br>    ),<br>  );<br>}</pre><h3>Step 4: Use It in the UI</h3><pre>class MyApp extends StatelessWidget {<br>  const MyApp({super.key});<br><br>  @override<br>  Widget build(BuildContext context) {<br>    final counter = context.watch&lt;CounterModel&gt;();<br><br>    return MaterialApp(<br>      home: Scaffold(<br>        appBar: AppBar(title: const Text(&#39;Provider Example&#39;)),<br>        body: Center(<br>          child: Text(<br>            &#39;Counter: ${counter.count}&#39;,<br>            style: const TextStyle(fontSize: 24),<br>          ),<br>        ),<br>        floatingActionButton: FloatingActionButton(<br>          onPressed: counter.increment,<br>          child: const Icon(Icons.add),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Now the same counter app works, but with much cleaner and shorter code.</p><h3>InheritedWidget vs Provider</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZRedZifKuealLdxnQZidVA.jpeg" /></figure><h3>When to Use What</h3><ul><li>Use <strong>InheritedWidget</strong> if you’re learning how Flutter’s widget tree and context work.</li><li>Use <strong>Provider</strong> for real apps — it’s easier, cleaner, and still built on the same foundation.</li></ul><h3>Final Thoughts</h3><p>If you understand InheritedWidget, you basically understand the <strong>core of Flutter’s state management system</strong>.<br> Provider just makes it less painful to write and maintain.</p><p>So next time someone asks what Provider does — you can smile and say, <em>“It’s just a friendly wrapper around InheritedWidget.” 😄</em></p><p>🚀 Thanks for reading! <br>If this post helped you understand Flutter a bit better, hit the ❤️ and follow for more dev-friendly Flutter tutorials. <br>🧠 Have a question or a topic you’d like me to cover next? Let me know in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=694edaece0a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Kotlin Flow: 5 Essential Patterns Every Developer Should Know]]></title>
            <link>https://medium.com/@rajmane5151_23114/mastering-kotlin-flow-5-essential-patterns-every-developer-should-know-e40e85f103e8?source=rss-6bc4fa104dfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/e40e85f103e8</guid>
            <category><![CDATA[kotlin-flow]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-beginners]]></category>
            <dc:creator><![CDATA[Abhijit Rajmane]]></dc:creator>
            <pubDate>Mon, 29 Sep 2025 17:16:21 GMT</pubDate>
            <atom:updated>2025-09-29T17:16:21.973Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*Rx-QGSK-7j0W59etkata8g.png" /></figure><h3>Why Use Flow?</h3><ul><li>A suspend function returns a <em>single</em> result a Flow&lt;T&gt;can emit <strong>multiple values over time</strong>.</li><li>It integrates seamlessly with Kotlin coroutines, so it’s non blocking and supports cancellation.</li><li>You get a rich set of operators (map, filter, combine, etc.) and error handling (catch, retry) built in.</li></ul><h3>🌊 1. Cold Flow (Basic Flow Pattern)</h3><p><strong>What it is:</strong><br> A Flow in Kotlin is <strong>cold</strong> by default it doesn’t emit values until it’s collected. This is the foundation of all Flow usage.<br><strong>When to use:</strong> Whenever you want a lazy, on-demand data stream.</p><pre>val numbersFlow = flow {<br>    for (i in 1..5) {<br>        delay(500)<br>        emit(i)<br>    }<br>}<br><br>suspend fun main() {<br>    numbersFlow.collect { value -&gt;<br>        println(&quot;Received: $value&quot;)<br>    }<br>}</pre><p><strong>Key points:</strong></p><ul><li>Emissions happen <strong>only when collected</strong>.</li><li>Each new collector triggers a fresh emission sequence.</li><li>Ideal for one-time computations or API calls.</li></ul><h3>🔁 2. Transforming Flows (map, filter, transform)</h3><p><strong>What it is:</strong><br> Use operators to modify, filter, or combine emissions before they reach the collector.<br><strong>When to use:</strong> Anytime you need to <strong>process or transform</strong> the stream.</p><pre>val transformedFlow = (1..5).asFlow()<br>    .filter { it % 2 == 0 }     // Keep even numbers<br>    .map { &quot;Value: $it&quot; }       // Transform to string<br><br>suspend fun main() {<br>    transformedFlow.collect { println(it) }<br>}</pre><p>💡 <strong>Pro Tip:</strong><br> Use transform{emit(…) }for complex logic (multiple emissions, side effects, etc.)</p><pre>val advanced = (1..5).asFlow().transform { value -&gt;<br>    emit(&quot;Start $value&quot;)<br>    emit(&quot;End $value&quot;)<br>}</pre><h3>⚡3. Combining Flows (zip, combine, flatMap)</h3><p><strong>What it is:</strong><br> Merge or combine multiple flows into one. This is a powerful reactive pattern.<br><strong>When to use:</strong> When you need to synchronize or merge multiple async data streams.</p><pre>val flowA = flowOf(1, 2, 3)<br>val flowB = flowOf(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;)<br><br>// zip: pairs emissions by index<br>val zipped = flowA.zip(flowB) { a, b -&gt; &quot;$a -&gt; $b&quot; }<br><br>// combine: emits when *any* upstream emits<br>val combined = flowA.combine(flowB) { a, b -&gt; &quot;$a + $b&quot; }</pre><p>📊 <strong>When to choose which:</strong></p><ul><li>zip → pair values <strong>by order</strong> (like List.zip()).</li><li>combine → react to the <strong>latest</strong> from each flow.</li><li>flatMapConcat/ flatMapMerge→ flatten nested flows.</li></ul><h3>🔄 4. StateFlow &amp; SharedFlow (Hot Streams)</h3><p><strong>What it is:</strong><br> Unlike cold flows, these are <strong>hot </strong>they emit values regardless of active collectors.<br><strong>When to use:</strong> For UI state, event buses, or broadcasting data to multiple collectors.</p><pre>val state = MutableStateFlow(0)<br><br>fun increment() {<br>    state.value++<br>}<br><br>suspend fun observeState() {<br>    state.collect { println(&quot;Current state: $it&quot;) }<br>}</pre><p>For events (not state), use SharedFlow:</p><pre>val events = MutableSharedFlow&lt;String&gt;()<br><br>suspend fun main() {<br>    launch { events.collect { println(&quot;Event: $it&quot;) } }<br>    events.emit(&quot;Hello World&quot;)<br>}</pre><p>📌 <strong>Best practices:</strong></p><ul><li>StateFlow → for continuous state (e.g. UI state, counter).<br>SharedFlow → for one-time events (e.g. navigation, notifications).</li></ul><h3>🧵 5. Flow + Retry, Catch, and Lifecycle Handling</h3><p><strong>What it is:</strong><br> Flows can gracefully handle errors and retry automatically perfect for network or database calls.<br><strong>When to use:</strong> Anytime you deal with unreliable sources (APIs, I/O).</p><pre>val safeFlow = flow {<br>    emit(fetchDataFromNetwork()) // might throw<br>}.retry(3) { e -&gt;<br>    e is IOException // retry up to 3 times if it&#39;s a network error<br>}.catch { e -&gt;<br>    emit(&quot;Fallback value: ${e.message}&quot;)<br>}<br><br>suspend fun main() {<br>    safeFlow.collect { println(it) }<br>}</pre><p>🔁 <strong>Other operators to know:</strong></p><ul><li>onStart{..}– do something before collecting.</li><li>onCompletion{..}– cleanup or log after completion.</li><li>timeout{…}– cancel flow if it takes too long.</li></ul><h4>Conclusion-</h4><p>Understanding the different Flow patterns in Kotlin is key to building reactive, scalable, and maintainable applications. <strong>Cold Flows</strong> give you lazy, on-demand data emission for tasks like API calls, while <strong>Transform Operators</strong> let you process and shape your data streams efficiently.</p><p>When dealing with multiple data sources, <strong>Combining Flows</strong> helps you merge and synchronize state seamlessly. For continuous, always on streams like UI updates or event handling, <strong>StateFlow</strong> and <strong>SharedFlow</strong> provide powerful hot emission solutions. Finally, incorporating <strong>Error Handling and Retry</strong> ensures your app stays resilient in real-world network conditions.</p><p>By mastering these patterns, you can write clean, robust, and reactive code that makes full use of Kotlin Flow’s capabilities turning complex asynchronous operations into elegant, predictable data pipelines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*n5vdd8xExeDEvo8KgAT2dQ.png" /></figure><p>🙌 <strong>Follow for More!</strong><br>If you found this helpful, leave a ❤️ and follow me for more tutorials on <strong>Kotlin</strong>,<strong> Jetpack Compose, UI design, and Android architecture</strong>.<br>🔔 Got ideas or questions? Drop them in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e40e85f103e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Complete Guide to Kotlin Coroutine Scopes]]></title>
            <link>https://medium.com/@rajmane5151_23114/complete-guide-to-kotlin-coroutine-scopes-76ba6543960e?source=rss-6bc4fa104dfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/76ba6543960e</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[threads]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-coroutines]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Abhijit Rajmane]]></dc:creator>
            <pubDate>Fri, 26 Sep 2025 17:17:15 GMT</pubDate>
            <atom:updated>2025-09-26T17:29:00.531Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uMa3AjQViENF_b0wmeLFQQ.png" /></figure><p>In Kotlin, <strong>coroutine scopes</strong> define <strong>the lifecycle and context of coroutines</strong>. Choosing the right scope is crucial to prevent memory leaks, uncontrolled coroutines, or crashes in your app.</p><h4>1. GlobalScope</h4><ul><li><strong>Description:</strong> Top-level scope that lives as long as the app does.</li><li><strong>Use case:</strong> Rarely only for background tasks that must outlive any component.</li><li><strong>Warning:</strong> Can easily lead to memory leaks if not handled properly.</li></ul><pre>fun main() {<br>    GlobalScope.launch {<br>        delay(1000)<br>        println(&quot;GlobalScope coroutine finished&quot;)<br>    }<br>    Thread.sleep(2000) // block main thread to see result<br>}</pre><p><strong>Tip:</strong> Avoid GlobalScope in Android apps, prefer structured scopes.</p><h4>2.CoroutineScope</h4><ul><li><strong>Description:</strong> Custom scope you can create anywhere must be managed manually.</li><li><strong>Use case:</strong> When you need a scope tied to a component or service.</li></ul><pre>val myScope = CoroutineScope(Dispatchers.Default)<br><br>fun main() {<br>    myScope.launch {<br>        println(&quot;Running in custom scope&quot;)<br>    }<br>}</pre><h4><strong>3. viewModelScope (Android-specific)</strong></h4><ul><li><strong>Description:</strong> Lifecycle-aware scope tied to a ViewModel.</li><li><strong>Use case:</strong> Automatic cancellation when ViewModel is cleared.</li></ul><pre>class MyViewModel : ViewModel() {<br>    fun fetchData() {<br>        viewModelScope.launch {<br>            val data = fetchDataFromNetwork()<br>            println(data)<br>        }<br>    }<br>}</pre><ul><li><strong>No need to cancel manually -</strong> Automatically cancels all coroutines when ViewModel is cleared</li></ul><h4><strong>4. </strong>lifecycleScope <strong>(Android-specific)</strong></h4><ul><li><strong>Description:</strong> Lifecycle-aware scope tied to an Activity or Fragment.</li><li><strong>Use case:</strong> Launch coroutines tied to UI components.</li></ul><pre>class MainActivity : AppCompatActivity() {<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        lifecycleScope.launch {<br>            repeat(5) { println(&quot;Coroutine running in lifecycleScope&quot;) }<br>        }<br>    }<br>}</pre><ul><li><strong>Automatically canceled -</strong> coroutines when the lifecycle ends.</li><li>Use <strong>lifecycle-aware scopes</strong> in Android (viewModelScope, lifecycleScope) to prevent memory leaks.</li></ul><h4>🙌 Follow for More!</h4><p>If you found this helpful, leave a ❤️ and <strong>follow me</strong> for more tutorials on <strong>Jetpack Compose</strong>, <strong>UI design</strong>, and <strong>Android architecture</strong>.</p><p>🔔 Got ideas or questions? Drop them in the comments!</p><p>Jetpack Compose, Kotlin, Android Development, NavigationJetpack Compose Kotlin Android Development Navigation</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76ba6543960e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SSL Pinning in Android with Kotlin: A Complete Guide]]></title>
            <link>https://medium.com/@rajmane5151_23114/ssl-pinning-in-android-with-kotlin-a-complete-guide-30d465f2fdda?source=rss-6bc4fa104dfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/30d465f2fdda</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Abhijit Rajmane]]></dc:creator>
            <pubDate>Fri, 26 Sep 2025 16:24:51 GMT</pubDate>
            <atom:updated>2025-09-26T16:24:51.602Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cY5NxJ_ulHXPIPPFtZHCXA.png" /></figure><h3>Table of Contents</h3><ol><li><a href="#what-is-ssl">What is SSL?</a></li><li><a href="#what-is-ssl-pinning">What is SSL Pinning?</a></li><li><a href="#ssl-pinning-works">How SSL Pinning Works</a></li><li><a href="#advantages">Advantages of SSL Pinning</a></li><li><a href="#considerations--best-practices">Considerations &amp; Best Practices</a></li></ol><h3>What is SSL?</h3><p><strong>SSL (Secure Socket Layer)</strong> is a protocol that secures communication between a client (like an Android app) and a server. It ensures:</p><ul><li><strong>Encryption</strong> — Your data is unreadable to attackers.</li><li><strong>Authentication</strong> — Confirms you’re communicating with the right server.</li><li><strong>Integrity</strong> — Ensures data isn’t altered during transmission.</li></ul><p>Modern SSL is now referred to as <strong>TLS (Transport Layer Security)</strong>, but the term SSL is still widely used.</p><h3>What is SSL Pinning?</h3><p><strong>SSL Pinning</strong> is a security technique that hardcodes your server’s certificate or public key inside your app.<br> When the app communicates with the server:</p><ul><li>It compares the server’s certificate with the pinned one.</li><li>If they match, the connection continues.</li><li>If not, the app blocks the connection — even if the certificate is valid.</li></ul><p>This protects against <strong>Man-in-the-Middle (MITM) attacks</strong>, fake CAs, and unauthorized proxies.</p><h3>How SSL Pinning Works</h3><ol><li>Your app holds a trusted certificate or public key (the “pin”).</li><li>When connecting to the server, the app compares the server’s certificate/public key with the pinned version.</li><li>If there’s a mismatch, the connection is rejected.</li><li>If it matches, the connection proceeds securely.</li></ol><p>Essentially, it adds a second layer of trust beyond the standard SSL handshake.</p><h3>Advantages of SSL Pinning</h3><ul><li>Prevents MITM attacks</li><li>Protects against compromised Certificate Authoriti<strong>es</strong></li><li>Ensures your app only talks to your trusted servers</li><li>Increases user trust and data safety</li></ul><h3>Considerations &amp; Best Practices</h3><ul><li><strong>Use public key pinning</strong> rather than full certificate pinning to avoid issues during certificate renewal.</li><li><strong>Pin multiple keys</strong> (old + new) for smoother certificate rotation.</li><li><strong>Store certificates in </strong><strong>res/raw</strong> to protect them from tampering.</li><li><strong>Have a fallback mechanism</strong> — if all pins fail, prompt for updates.</li><li><strong>Regularly update pins</strong> to match your backend server.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30d465f2fdda" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Kotlin Context Parameters]]></title>
            <link>https://medium.com/@rajmane5151_23114/getting-started-with-kotlin-context-parameters-808ee578f939?source=rss-6bc4fa104dfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/808ee578f939</guid>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack]]></category>
            <dc:creator><![CDATA[Abhijit Rajmane]]></dc:creator>
            <pubDate>Sat, 20 Sep 2025 16:52:29 GMT</pubDate>
            <atom:updated>2025-09-20T16:52:29.645Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QkQNG9beV-lXQro4p-vE-w.png" /></figure><p>Kotlin keeps evolving, and one of its latest experimental features — <strong>context parameters</strong> — makes dependency passing and DSL creation much cleaner. If you’ve ever struggled with long parameter lists or clunky dependency injection, context parameters are worth learning.</p><h3>🤔 What Are Context Parameters?</h3><p>Context parameters allow you to declare functions that require certain values (like services, configuration, or loggers) without explicitly threading them through every function call.</p><p>Think of them as a structured way to say: <em>“This function needs these things available in its scope.”</em></p><h3>🛠 Step 1: Enable Context Parameters</h3><p>At the time of writing, context parameters are still <strong>experimental</strong>, so you need to opt-in:</p><pre>// In your build.gradle.kts<br>kotlin {<br>    sourceSets.all {<br>        languageSettings.optIn(&quot;kotlin.experimental.ExperimentalContextReceivers&quot;)<br>    }<br>}</pre><h3>🛠 Step 2: Basic Example</h3><p>Here’s how you might use a context parameter to inject a Logger:</p><pre>class Logger {<br>    fun log(message: String) = println(&quot;LOG: $message&quot;)<br>}<br><br>context(Logger)<br>fun greet(name: String) {<br>    log(&quot;Greeting $name&quot;)<br>    println(&quot;Hello, $name!&quot;)<br>}<br><br>fun main() {<br>    val logger = Logger()<br>    with(logger) {<br>        greet(&quot;Kotlin&quot;)<br>    }<br>}</pre><p><strong>How it works:</strong></p><ul><li>context(Logger) means greet requires a Logger in its calling scope.</li><li>Inside main, we call with(logger) to supply that dependency.</li></ul><p>No need to pass logger around explicitly!</p><h3>🛠 Step 3: Multiple Context Parameters</h3><p>You can require more than one:</p><pre>class Config(val appName: String)<br><br>context(Logger, Config)<br>fun runApp() {<br>    log(&quot;Starting $appName&quot;)<br>}</pre><p>This makes it easier to design composable APIs without cluttered function signatures.</p><h3>🌍 Real-World Use Cases</h3><ul><li><strong>Dependency Injection</strong>: Pass loggers, services, or configs naturally.</li><li><strong>DSLs</strong>: Cleaner builder syntax without long argument chains.</li><li><strong>Cross-cutting concerns</strong>: Logging, metrics, or security contexts.</li></ul><h3>🚀 Conclusion</h3><p>Context parameters are still experimental, but they unlock powerful new patterns for cleaner, more expressive Kotlin. If you’re already using Kotlin for backend or multiplatform projects, keep an eye on this feature — it could reshape how you structure your code.</p><h3>🙌 Follow for More!</h3><p>If you found this helpful, leave a ❤️ and <strong>follow me</strong> for more tutorials on <strong>Jetpack Compose</strong>, <strong>UI design</strong>, and <strong>Android architecture</strong>.</p><p>🔔 Got ideas or questions? Drop them in the comments!</p><p>Jetpack Compose, Kotlin, Android Development, NavigationJetpack Compose Kotlin Android Development Navigation</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=808ee578f939" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Kotlin Multiplatform and Compose Multiplatform]]></title>
            <link>https://medium.com/@rajmane5151_23114/getting-started-with-kotlin-multiplatform-and-compose-multiplatform-bdc981faba9e?source=rss-6bc4fa104dfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdc981faba9e</guid>
            <dc:creator><![CDATA[Abhijit Rajmane]]></dc:creator>
            <pubDate>Sat, 20 Sep 2025 15:59:41 GMT</pubDate>
            <atom:updated>2025-09-20T17:01:30.540Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NfoHjIhYx39vR_MjAlBBJg.png" /></figure><p>Kotlin has grown far beyond Android. With <strong>Kotlin Multiplatform (KMP)</strong> and <strong>Compose Multiplatform</strong>, you can now share business logic <em>and</em> UI across Android, iOS, desktop, and even web — all from one codebase.</p><p>In this tutorial, we’ll build a simple cross-platform counter app to explore the fundamentals.</p><h3>🔧 Prerequisites</h3><ul><li><strong>IntelliJ IDEA</strong> (Community or Ultimate) with the <strong>Kotlin Multiplatform plugin</strong> installed</li><li>JDK 17 or later</li><li>(Optional) Xcode for iOS targets</li></ul><h3>🛠 Step 1: Create a Kotlin Multiplatform Project</h3><ol><li>Open IntelliJ → <em>New Project</em>.</li><li>Select <strong>Kotlin Multiplatform → Compose Multiplatform template</strong>.</li><li>Choose your targets (Android, iOS, Desktop, Web). For this tutorial, select <strong>Desktop + Android</strong> to keep things light.</li></ol><p>Your project will generate a shared module (shared) and platform-specific modules.</p><h3>📦 Step 2: Define Shared Business Logic</h3><p>Inside the shared module, add a simple counter class:</p><pre>package com.example.shared<br><br>class Counter {<br>    private var count = 0<br><br>    fun increment() = ++count<br>    fun decrement() = --count<br>    fun value() = count<br>}</pre><h3>🎨 Step 3: Build a Compose UI</h3><p>In the same shared module, create a Composable function to display the counter:</p><pre>package com.example.shared<br><br>import androidx.compose.material.*<br>import androidx.compose.runtime.*<br><br>@Composable<br>fun CounterApp() {<br>    var counter by remember { mutableStateOf(Counter()) }<br>    val value = remember { mutableStateOf(counter.value()) }<br><br>    Column {<br>        Text(&quot;Count: ${value.value}&quot;, style = MaterialTheme.typography.h5)<br>        Row {<br>            Button(onClick = { value.value = counter.increment() }) {<br>                Text(&quot;Increment&quot;)<br>            }<br>            Button(onClick = { value.value = counter.decrement() }) {<br>                Text(&quot;Decrement&quot;)<br>            }<br>        }<br>    }<br>}</pre><h3>📱 Step 4: Run on Desktop</h3><p>In the desktopApp module, update Main.kt:</p><pre>import androidx.compose.ui.window.Window<br>import androidx.compose.ui.window.application<br>import com.example.shared.CounterApp<br><br>fun main() = application {<br>    Window(onCloseRequest = ::exitApplication) {<br>        CounterApp()<br>    }<br>}<br></pre><p>Run → you’ll see your Compose window with a working counter app on desktop.</p><h3>📱 Step 5: Run on Android</h3><p>In androidApp/src/main/java/.../MainActivity.kt:</p><pre>import android.os.Bundle<br>import androidx.activity.ComponentActivity<br>import androidx.activity.compose.setContent<br>import com.example.shared.CounterApp<br><br>class MainActivity : ComponentActivity() {<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContent {<br>            CounterApp()<br>        }<br>    }<br>}</pre><p>Run on an Android emulator → same UI, same logic.</p><h3>🌍 Next Steps</h3><ul><li>Add <strong>iOS target</strong> with Swift interop.</li><li>Use <strong>Compose for Web</strong> for browser support.</li><li>Integrate real logic (e.g., API calls, databases) inside the shared module.</li></ul><h3>🚀 Conclusion</h3><p>With Kotlin Multiplatform and Compose Multiplatform, you write <strong>once</strong> and run <strong>everywhere</strong>. The same code powers Android, iOS, desktop, and web apps — reducing duplication, speeding up development, and making maintenance easier.</p><p>If you’re an Android dev, this is the smoothest path into truly cross-platform development.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdc981faba9e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sealed Classes in Kotlin with Examples]]></title>
            <link>https://medium.com/@rajmane5151_23114/sealed-classes-in-kotlin-with-examples-89d75606d26b?source=rss-6bc4fa104dfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/89d75606d26b</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[sealed-classes]]></category>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Abhijit Rajmane]]></dc:creator>
            <pubDate>Sat, 20 Sep 2025 15:19:28 GMT</pubDate>
            <atom:updated>2025-09-20T15:51:58.041Z</atom:updated>
            <content:encoded><![CDATA[<p>When working with Kotlin, you’ll often encounter situations where a type can have a limited set of possible values. For example, representing different states of a UI (loading, success, error) or modeling results from a network call.</p><p>This is where <strong>sealed classes</strong> shine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*udYRG2X_saMXZhslzoAQmw.png" /></figure><h3>What is a Sealed Class?</h3><p>A <strong>sealed class</strong> in Kotlin is a special kind of class used to represent restricted class hierarchies. It allows you to define a set of subclasses in a controlled way. Unlike regular inheritance, all subclasses of a sealed class must be <strong>defined in the same file</strong>.</p><p>Think of sealed classes as enums on steroids: while enums can only hold a fixed set of constants, sealed classes can hold different types with different data.</p><h3>Basic Syntax</h3><pre>sealed class Result<br><br>data class Success(val data: String) : Result()<br>data class Error(val exception: Exception) : Result()<br>object Loading : Result()</pre><p>Here, Result is a sealed class that can only be one of the following:</p><ul><li>Success → holds some data</li><li>Error → holds an exception</li><li>Loading → represents a loading state</li></ul><h3>Why Use Sealed Classes?</h3><ol><li><strong>Type Safety</strong> — The compiler knows all possible subclasses, so when you use when expressions, you get exhaustive checks.</li><li><strong>Readability</strong> — Makes code easier to understand by modeling states clearly.</li><li><strong>Flexibility</strong> — Unlike enums, you can store data inside each state.</li></ol><h3>Example: Handling API Response</h3><pre>sealed class ApiResponse&lt;out T&gt; {<br>    data class Success&lt;out T&gt;(val data: T) : ApiResponse&lt;T&gt;()<br>    data class Error(val message: String) : ApiResponse&lt;Nothing&gt;()<br>    object Loading : ApiResponse&lt;Nothing&gt;()<br>}<br><br>fun fetchUser(): ApiResponse&lt;String&gt; {<br>    return ApiResponse.Success(&quot;John Doe&quot;)<br>}<br><br>fun main() {<br>    val response = fetchUser()<br><br>    when (response) {<br>        is ApiResponse.Success -&gt; println(&quot;User: ${response.data}&quot;)<br>        is ApiResponse.Error -&gt; println(&quot;Error: ${response.message}&quot;)<br>        ApiResponse.Loading -&gt; println(&quot;Loading...&quot;)<br>    }<br>}</pre><h3>Output:</h3><pre>User: John Doe</pre><p>Notice how the when expression covers all possible cases. If you forget one, the compiler will warn you!</p><h3>Difference Between Enum and Sealed Class</h3><ul><li><strong>Enums</strong>: Best for simple constants with no or little associated data.</li><li><strong>Sealed Classes</strong>: Best for representing states with different types of data.</li></ul><h3>Real-World Use Cases</h3><ul><li>Representing <strong>network call results</strong> (Success, Error, Loading)</li><li>Modeling <strong>UI states</strong> (e.g., Empty, Content, Loading, Error)</li><li>Defining <strong>navigation screens</strong> in a type-safe way</li></ul><h3>Final Thoughts</h3><p>Sealed classes are a powerful feature in Kotlin that bring clarity and safety to your code, especially when working with states. Next time you find yourself modeling different outcomes, consider using a sealed class — it might save you from messy if-else chains.</p><h3>🙌 Follow for More!</h3><p>If you found this helpful, leave a ❤️ and <strong>follow me</strong> for more tutorials on <strong>Jetpack Compose</strong>, <strong>UI design</strong>, and <strong>Android architecture</strong>.</p><p>🔔 Got ideas or questions? Drop them in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89d75606d26b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Passing Data Between Screens in Jetpack Compose: A Comprehensive Guide]]></title>
            <link>https://medium.com/@rajmane5151_23114/passing-data-between-screens-in-jetpack-compose-a-comprehensive-guide-03fed7cc6235?source=rss-6bc4fa104dfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/03fed7cc6235</guid>
            <category><![CDATA[android-navigation]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[navigation-component]]></category>
            <category><![CDATA[jetpack-compose-tutorial]]></category>
            <category><![CDATA[android-jetpack]]></category>
            <dc:creator><![CDATA[Abhijit Rajmane]]></dc:creator>
            <pubDate>Sat, 26 Jul 2025 07:44:13 GMT</pubDate>
            <atom:updated>2025-07-26T07:44:13.249Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aI1JpYLrxVLZhPbM" /></figure><p>When building Android apps with <strong>Jetpack Compose</strong>, it’s common to navigate between screens while passing data. While simple types like strings or integers can be passed as arguments, handling <strong>complex objects</strong> such as user profiles requires a different approach.</p><p>In this tutorial, we’ll walk through creating a <strong>Sign-Up → Profile</strong> flow where user data is collected on one screen and displayed on another using a <strong>Shared ViewModel</strong>.</p><h3>Why Use a Shared ViewModel?</h3><ul><li>Navigation arguments support only simple data types.</li><li>Passing a serialized object via navigation is possible, but not ideal for reactive UIs.</li><li>A <strong>Shared ViewModel</strong> survives configuration changes and allows multiple screens to access the same data easily.</li></ul><h3>1. Create the User Model</h3><p>We’ll create a simple data class to represent our user.</p><pre>data class UserModel(<br>    val name: String,<br>    val email: String,<br>    val address: String<br>)</pre><h3>2. Create a Shared ViewModel</h3><p>The SharedViewModel will hold our UserModel instance and expose it as State, so any screen observing it will automatically update when data changes.</p><pre>class SharedViewModel : ViewModel() {<br>    private val _user = mutableStateOf&lt;UserModel?&gt;(null)<br>    val user: State&lt;UserModel?&gt; = _user<br><br>    fun setUser(newUser: UserModel) {<br>        _user.value = newUser<br>    }<br>}</pre><h3>3. Set up Navigation in MainActivity</h3><p>We’ll use the <strong>Navigation Compose</strong> library to switch between screens and share the same ViewModel instance.</p><pre>class MainActivity : ComponentActivity() {<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContent {<br>            MyApp()<br>        }<br>    }<br>}<br><br>@Composable<br>fun MyApp() {<br>    val navController = rememberNavController()<br>    val sharedViewModel: SharedViewModel = viewModel()<br><br>    NavHost(navController = navController, startDestination = &quot;signup_screen&quot;) {<br>        composable(&quot;signup_screen&quot;) {<br>            SignUpScreen(<br>                onSignUp = { user -&gt;<br>                    sharedViewModel.setUser(user)<br>                    navController.navigate(&quot;profile_screen&quot;)<br>                }<br>            )<br>        }<br><br>        composable(&quot;profile_screen&quot;) {<br>            ProfileScreen(sharedViewModel)<br>        }<br>    }<br>}</pre><h3>4. Build the Sign-Up Screen</h3><p>The <strong>SignUpScreen</strong> collects user input and calls the onSignUp lambda when the user presses the <strong>Sign Up</strong> button.</p><pre>@Composable<br>fun SignUpScreen(onSignUp: (UserModel) -&gt; Unit) {<br>    var name by rememberSaveable { mutableStateOf(&quot;&quot;) }<br>    var email by rememberSaveable { mutableStateOf(&quot;&quot;) }<br>    var address by rememberSaveable { mutableStateOf(&quot;&quot;) }<br><br>    Scaffold { innerPadding -&gt;<br>        Column(<br>            modifier = Modifier<br>                .fillMaxSize()<br>                .padding(16.dp)<br>                .verticalScroll(rememberScrollState()),<br>            horizontalAlignment = Alignment.CenterHorizontally,<br>            verticalArrangement = Arrangement.spacedBy(16.dp)<br>        ) {<br>            Text(&quot;Create Account&quot;, style = MaterialTheme.typography.headlineMedium)<br><br>            OutlinedTextField(value = name, onValueChange = { name = it }, label = { Text(&quot;Name&quot;) })<br>            OutlinedTextField(value = email, onValueChange = { email = it }, label = { Text(&quot;Email&quot;) })<br>            OutlinedTextField(value = address, onValueChange = { address = it }, label = { Text(&quot;Address&quot;) })<br><br>            Button(<br>                onClick = {<br>                    if (name.isNotBlank() &amp;&amp; email.isNotBlank() &amp;&amp; address.isNotBlank()) {<br>                        onSignUp(UserModel(name, email, address))<br>                    }<br>                }<br>            ) {<br>                Text(&quot;Sign Up&quot;)<br>            }<br>        }<br>    }<br>}</pre><h3>5. Build the Profile Screen</h3><p>The <strong>ProfileScreen</strong> reads user data from the SharedViewModel and displays it.</p><pre>@Composable<br>fun ProfileScreen(sharedViewModel: SharedViewModel) {<br>    val user by sharedViewModel.user<br><br>    if (user != null) {<br>        Column(<br>            modifier = Modifier<br>                .fillMaxSize()<br>                .padding(16.dp),<br>            horizontalAlignment = Alignment.CenterHorizontally,<br>            verticalArrangement = Arrangement.Center<br>        ) {<br>            Text(&quot;Profile&quot;, style = MaterialTheme.typography.headlineMedium)<br>            Text(&quot;Name: ${user!!.name}&quot;)<br>            Text(&quot;Email: ${user!!.email}&quot;)<br>            Text(&quot;Address: ${user!!.address}&quot;)<br>        }<br>    } else {<br>        Box(<br>            modifier = Modifier.fillMaxSize(),<br>            contentAlignment = Alignment.Center<br>        ) {<br>            Text(&quot;No user data available&quot;)<br>        }<br>    }<br>}</pre><h3>How It Works</h3><ol><li><strong>User enters data</strong> on SignUpScreen.</li><li>Pressing <strong>Sign Up</strong> calls onSignUp(UserModel(...)).</li><li>The SharedViewModel stores the user object.</li><li>Navigation moves to ProfileScreen.</li><li>ProfileScreen reads the user data from the SharedViewModel and displays it.</li></ol><h3>Conclusion</h3><ul><li>A <strong>Shared ViewModel</strong> is the simplest and most reliable way to pass complex data between screens in Jetpack Compose.</li><li>It provides <strong>reactive data updates</strong>, <strong>persists across configuration changes</strong>, and keeps navigation clean.</li><li>You can now create multi-screen Compose apps where <strong>data flows seamlessly</strong>.</li></ul><p>I hope this comprehensive guide helps you decide the best way to handle data passing between screens in your Jetpack Compose applications and please feel free to comment if you know any other ways to do this. Thanks for your time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=03fed7cc6235" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jetpack Compose Navigation: Pass Data Between Screens (Kotlin Tutorial)]]></title>
            <link>https://medium.com/@rajmane5151_23114/jetpack-compose-navigation-passing-data-between-screens-ee7fd1cd8841?source=rss-6bc4fa104dfa------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee7fd1cd8841</guid>
            <dc:creator><![CDATA[Abhijit Rajmane]]></dc:creator>
            <pubDate>Tue, 22 Jul 2025 10:33:31 GMT</pubDate>
            <atom:updated>2025-07-22T14:58:30.617Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial, we’ll build a simple Android app using <strong>Jetpack Compose</strong> where the user enters their <strong>Name</strong> and <strong>Address</strong> on one screen and views th data on a second screen. This is a perfect starting point to understand <strong>navigation</strong>, <strong>argument passing</strong>, and clean UI in Compose.</p><h3>🚀 What You’ll Learn</h3><ul><li>Learn <strong>Compose Navigation</strong> with arguments.</li><li>Handle <strong>data passing</strong> between screens.</li><li>Build a clean UI with headings, text fields, and buttons.</li><li>Real-world pattern without a shared ViewModel</li></ul><h3>Final Output</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*9lVCRPEnDj6W57CAF7WVlg.png" /><figcaption>Screen One</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*37Nd8hMLgVZAfrWubzAIlg.png" /><figcaption>Screen Two</figcaption></figure><h3>1. Setting Up Navigation</h3><p>First, create your MainActivity and set up the NavHost with two routes:</p><pre>class MainActivity : ComponentActivity() {<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContent {<br>            MaterialTheme {<br>                Surface {<br>                    MainApp()<br>                }<br>            }<br>        }<br>    }<br>}<br>@Composable<br>fun MainApp() {<br>    val navController = rememberNavController()<br><br>    NavHost(navController = navController, startDestination = &quot;screen_one&quot;) {<br>        composable(&quot;screen_one&quot;) {<br>            ScreenOne(navController)<br>        }<br>        composable(<br>            &quot;screen_two/{name}/{address}&quot;,<br>            arguments = listOf(<br>                navArgument(&quot;name&quot;) { type = NavType.StringType },<br>                navArgument(&quot;address&quot;) { type = NavType.StringType }<br>            )<br>        ) { backStackEntry -&gt;<br>            val name = backStackEntry.arguments?.getString(&quot;name&quot;) ?: &quot;&quot;<br>            val address = backStackEntry.arguments?.getString(&quot;address&quot;) ?: &quot;&quot;<br>            SecondScreen(name, address)<br>        }<br>    }<br>}</pre><p>Here, screen_two receives name and address as arguments.</p><h3>2. Screen One — Collecting User Input</h3><pre>@Composable<br>fun ScreenOne(navController: NavHostController) {<br>    var name by remember { mutableStateOf(&quot;&quot;) }<br>    var address by remember { mutableStateOf(&quot;&quot;) }<br><br>    Column(<br>        modifier = Modifier<br>            .fillMaxSize()<br>            .padding(16.dp),<br>        verticalArrangement = Arrangement.Top,<br>        horizontalAlignment = Alignment.CenterHorizontally<br>    ) {<br>        Text(<br>            text = &quot;Screen One&quot;,<br>            style = MaterialTheme.typography.headlineMedium,<br>            modifier = Modifier<br>                .fillMaxWidth()<br>                .padding(bottom = 24.dp),<br>            textAlign = TextAlign.Center<br>        )<br><br>        Spacer(modifier = Modifier.height(24.dp))<br><br>        TextField(<br>            value = name,<br>            onValueChange = { name = it },<br>            label = { Text(&quot;Name&quot;) },<br>            singleLine = true,<br>            modifier = Modifier.fillMaxWidth()<br>        )<br><br>        Spacer(modifier = Modifier.height(16.dp))<br><br>        TextField(<br>            value = address,<br>            onValueChange = { address = it },<br>            label = { Text(&quot;Address&quot;) },<br>            modifier = Modifier.fillMaxWidth()<br>        )<br><br>        Spacer(modifier = Modifier.height(24.dp))<br><br>         Button(<br>            onClick = {<br>                val encodedName = Uri.encode(name)<br>                val encodedAddress = Uri.encode(address)<br>                navController.navigate(&quot;screen_two/$encodedName/$encodedAddress&quot;)<br>            },<br>            modifier = Modifier.fillMaxWidth()<br>        ) {<br>            Text(&quot;Submit&quot;)<br>        }<br>     <br>    }<br>}</pre><h3>3. Screen Two — Displaying Passed Data</h3><pre>@Composable<br>fun SecondScreen(name: String, address: String) {<br>    Column(<br>        modifier = Modifier<br>            .fillMaxSize()<br>            .padding(16.dp),<br>        verticalArrangement = Arrangement.Top,<br>        horizontalAlignment = Alignment.CenterHorizontally<br>    ) {<br>        Text(<br>            text = &quot;Screen Two&quot;,<br>            style = MaterialTheme.typography.headlineMedium,<br>            modifier = Modifier<br>                .fillMaxWidth()<br>                .padding(bottom = 24.dp),<br>            textAlign = TextAlign.Center<br>        )<br>    }<br><br>    Column(<br>        modifier = Modifier<br>            .fillMaxSize()<br>            .padding(16.dp),<br>        verticalArrangement = Arrangement.Center,<br>        horizontalAlignment = Alignment.CenterHorizontally<br>    ) {<br>        Text(<br>            text = &quot;Name: $name&quot;,<br>            style = MaterialTheme.typography.headlineSmall<br>        )<br>        Spacer(modifier = Modifier.height(8.dp))<br>        Text(<br>            text = &quot;Address: $address&quot;,<br>            style = MaterialTheme.typography.bodyLarge<br>        )<br>    }<br>}</pre><h3>4. How It Works</h3><ol><li>User enters Name and Address on <strong>Screen One</strong>.</li><li>On clicking <strong>Submit</strong>, we encode the values and navigate to <strong>Screen Two</strong>.</li><li><strong>Screen Two</strong> extracts arguments from the navigation route and displays them.</li></ol><h3>Conclusion</h3><p>We built a simple two-screen app using Jetpack Compose Navigation, passing user data securely between screens.<br> This approach is lightweight, doesn’t require a shared ViewModel, and handles strings safely.</p><h3>Next Steps</h3><ul><li>Add validation (e.g., non-empty fields).</li><li>Use a <strong>shared ViewModel</strong> for more complex data.</li><li>Explore <strong>Navigation with Safe Args</strong> for type safety.</li></ul><h3>🙌 Follow for More!</h3><p>If you found this helpful, leave a ❤️ and <strong>follow me</strong> for more tutorials on <strong>Jetpack Compose</strong>, <strong>UI design</strong>, and <strong>Android architecture</strong>.</p><p>🔔 Got ideas or questions? Drop them in the comments!</p><p>Jetpack Compose, Kotlin, Android Development, NavigationJetpack Compose Kotlin Android Development Navigation</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee7fd1cd8841" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>