<?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 Mayur Waghmare on Medium]]></title>
        <description><![CDATA[Stories by Mayur Waghmare on Medium]]></description>
        <link>https://medium.com/@waghmaremayur855?source=rss-b3f04ce96171------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vM21cPQnT6hPDiyCCaCDEg.jpeg</url>
            <title>Stories by Mayur Waghmare on Medium</title>
            <link>https://medium.com/@waghmaremayur855?source=rss-b3f04ce96171------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 19:24:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@waghmaremayur855/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[Mobile App Data Storage Options (Android, iOS, Flutter)]]></title>
            <link>https://medium.com/mobile-innovation-network/mobile-app-data-storage-options-android-ios-flutter-9af5a086ce2a?source=rss-b3f04ce96171------2</link>
            <guid isPermaLink="false">https://medium.com/p/9af5a086ce2a</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[data-storage]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[sharedpreferences]]></category>
            <category><![CDATA[options]]></category>
            <dc:creator><![CDATA[Mayur Waghmare]]></dc:creator>
            <pubDate>Tue, 07 Oct 2025 09:38:38 GMT</pubDate>
            <atom:updated>2025-10-22T09:31:42.140Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*9FzT8vwlk7ITVZSTkDT8Tg.jpeg" /></figure><p>In every mobile app, <strong>data storage</strong> plays a crucial role — from saving user preferences to managing large datasets. Choosing the right method ensures better <strong>performance, scalability, and security</strong>.</p><p>In this article, we’ll explore the best data storage options available across <strong>Android</strong>, <strong>iOS</strong>, and <strong>Flutter</strong> — with simple explanations and code examples to help you decide which one fits your needs. 🚀</p><h3>🔹 Why Data Storage Matters</h3><ul><li><strong>Essential for Apps:</strong> User preferences, files, tokens, and datasets all rely on proper storage.</li><li><strong>Platform-Specific Tools:</strong> Each platform offers unique APIs and frameworks.</li><li><strong>Secure &amp; Efficient:</strong> The right choice improves app performance and data safety.</li><li><strong>Versatile Options:</strong> From simple key-value stores to full-fledged databases.</li></ul><h3>📱 Android: Data Storage Options</h3><h3>1. SharedPreferences 🗝️</h3><p><strong>Purpose:</strong> Store lightweight key-value pairs (e.g., user preferences or settings).</p><pre>val sharedPreferences = context.getSharedPreferences(&quot;AppPrefs&quot;, Context.MODE_PRIVATE)<br>sharedPreferences.edit().putString(&quot;username&quot;, &quot;JohnDoe&quot;).apply()</pre><p>✅ <strong>Pros:</strong> Easy to use, no external setup<br>❌ <strong>Cons:</strong> Not suitable for large or complex data</p><h3>2. DataStore ⚡ (Modern Replacement for SharedPreferences)</h3><p><strong>Purpose:</strong> A coroutine-based, safer, and more efficient solution.</p><pre>implementation &quot;androidx.datastore:datastore-preferences:1.0.0&quot;</pre><p>✅ <strong>Pros:</strong> Asynchronous, avoids data corruption<br>❌ <strong>Cons:</strong> Relatively new, Steep learning curve</p><h3>3. Room Database 🏠</h3><p><strong>Purpose:</strong> Manage structured relational data using type-safe queries.</p><pre>implementation &quot;androidx.room:room-runtime:2.5.0&quot;<br>kapt &quot;androidx.room:room-compiler:2.5.0&quot;</pre><p>✅ <strong>Pros:</strong> Supports Kotlin coroutines &amp; Flow, reduces boilerplate<br>❌ <strong>Cons:</strong> Requires setup and learning curve</p><h3>4. EncryptedSharedPreferences 🔒(Deprecated)</h3><p><strong>Purpose:</strong> Store sensitive data securely (like tokens or passwords).</p><pre>implementation &quot;androidx.security:security-crypto:1.1.0-alpha03&quot;</pre><p>✅ <strong>Pros:</strong> Fully encrypted and highly secure<br>❌ <strong>Cons:</strong> Deprecated.</p><h3>🍎 iOS: Data Storage Options</h3><h4>1. UserDefaults 🛠️</h4><blockquote><strong><em>Purpose:</em></strong><em> Store small key-value pairs like user settings.</em></blockquote><pre>UserDefaults.standard.set(&quot;JohnDoe&quot;, forKey: &quot;username&quot;)</pre><p>✅ <strong>Pros:</strong> Simple and lightweight<br>❌ <strong>Cons:</strong> Not for large or structured data</p><h4>2. Core Data 📊</h4><blockquote><strong><em>Purpose:</em></strong><em> Manage large datasets with object-relational mapping.<br></em><strong><em>Dependency:</em></strong><em> Built into iOS.</em></blockquote><p>✅ <strong>Pros:</strong> Powerful querying, great performance<br>❌ <strong>Cons:</strong> Steep learning curve</p><h4>3. Keychain 🔑</h4><blockquote><strong><em>Purpose:</em></strong><em> Store sensitive information like passwords securely.<br></em><strong><em>Dependency:</em></strong><em> Use the </em><em>KeychainAccess library for easier integration.</em></blockquote><p>✅ <strong>Pros:</strong> Encrypted and secure<br>❌ <strong>Cons:</strong> Limited storage</p><h4>4. iCloud ☁️</h4><blockquote><strong><em>Purpose:</em></strong><em> Store data in the cloud for syncing across devices.<br></em><strong><em>Dependency:</em></strong><em> Use CloudKit.</em></blockquote><p>✅ <strong>Pros:</strong> Enables seamless cross-device sync<br>❌ <strong>Cons:</strong> Requires internet and setup complexity</p><h3>🛠️ Flutter: Data Storage Options</h3><h4>1. Shared Preferences 🗝️</h4><pre>shared_preferences: ^2.0.15</pre><p>✅ <strong>Pros:</strong> Perfect for small, simple data<br>❌ <strong>Cons:</strong> Not for large or structured storage</p><h4>2. <strong>Hive 🐝</strong></h4><pre>hive: ^2.2.3<br>hive_flutter: ^1.1.0</pre><p>✅ <strong>Pros:</strong> Fast, lightweight NoSQL database<br>❌ <strong>Cons:</strong> Not suitable for relational data</p><h4>3. <strong>sqflite 📄</strong></h4><pre>sqflite: ^2.0.0+4</pre><p>✅ <strong>Pros:</strong> Full SQL support, reliable<br>❌ <strong>Cons:</strong> Requires manual query writing</p><h4>4. Secure Storage 🔐</h4><pre>flutter_secure_storage: ^5.0.2</pre><p>✅ <strong>Pros:</strong> Encrypted and secure</p><h3>💡 When to Use Each Solution?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*MCdhGERnFs1ySn81E6APYQ.avif" /></figure><p>Thank you for taking the time to read this article. If you found the information valuable, please consider giving it a clap or sharing it with others who might benefit from it.</p><p><em>Any </em><strong><em>Suggestions</em></strong><em> are welcome. If you need any </em><strong><em>help</em></strong><em> or have questions for Code Contact US. You can follow us on </em><a href="https://www.linkedin.com/showcase/99983594/admin/feed/posts"><strong><em>LinkedIn</em></strong></a><strong><em> </em></strong>f<em>or more updates </em>🔔</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9af5a086ce2a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mobile-innovation-network/mobile-app-data-storage-options-android-ios-flutter-9af5a086ce2a">Mobile App Data Storage Options (Android, iOS, Flutter)</a> was originally published in <a href="https://medium.com/mobile-innovation-network">Mobile Innovation Network</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Fixing the Play Store Warning: “Recompile Your App with 16 KB Native Library Alignment”]]></title>
            <link>https://medium.com/mobile-innovation-network/fixing-the-play-store-warning-recompile-your-app-with-16-kb-native-library-alignment-8cea8119df3c?source=rss-b3f04ce96171------2</link>
            <guid isPermaLink="false">https://medium.com/p/8cea8119df3c</guid>
            <category><![CDATA[warning]]></category>
            <category><![CDATA[google-play-store]]></category>
            <category><![CDATA[google-playstore-error]]></category>
            <category><![CDATA[16-kb-page-size]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Mayur Waghmare]]></dc:creator>
            <pubDate>Mon, 06 Oct 2025 09:35:40 GMT</pubDate>
            <atom:updated>2025-10-06T11:53:53.011Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*a8S2HwNaPNE5qOAV1DhzFA.jpeg" /></figure><p>If you’re building Android apps and recently uploaded a bundle (.aab) to the Play Console, you might’ve seen this warning:</p><blockquote><strong><em>“This App Bundle contains native code, and you haven’t uploaded the debug symbols. Also, your native libraries are not aligned to 16 KB. Recompile your app with 16 KB native library alignment.”</em></strong></blockquote><p>In this article, I’ll walk you through what this warning means, why it matters, and how to fix it — step by step.</p><p><strong>🧠 What Does This Warning Mean?</strong></p><p>Your app contains <strong>native .so libraries</strong> (e.g., from the NDK or 3rd-party SDKs), and Android expects them to be <strong>aligned on 16 KB boundaries</strong> for optimized performance.</p><p>Before Android 6.0, 4 KB alignment was enough. Now, ART (Android Runtime) uses memory mapping, and <strong>misaligned libraries</strong> can lead to:</p><ul><li>Increased memory usage</li><li>Slower app startup</li><li>Poor runtime performance</li></ul><h4><strong>✅ The Fix: Rebuild with Proper Alignment</strong></h4><p><strong>1️⃣ Update gradle.properties</strong></p><p>Ensure native libraries are <strong>not compressed</strong> in your app bundle:</p><pre>android.bundle.enableNativeLibraryCompression=false</pre><p>This allows proper alignment in the .aab.</p><p><strong>2️⃣ Optional: Keep Debug Symbols</strong></p><p>In your build.gradle (app-level), update packagingOptions like this:</p><pre>android {<br>    packagingOptions {<br>        jniLibs {<br>            keepDebugSymbols += &quot;**/*.so&quot;<br>        }<br>    }<br>}</pre><p>This is useful if you want to upload debug symbols to Play Console for better crash reporting.</p><p><strong>3️⃣ Clean and Rebuild the Bundle</strong></p><p>Run the following in your terminal:</p><pre>./gradlew clean bundleRelease</pre><p>This creates a new .aab with 16 KB alignment (if settings are correct).</p><h4><strong>🧪 How to Verify Alignment</strong></h4><p>Now let’s verify your .aab using the zipalign tool.</p><p><strong>Step 1: Find zipalign</strong></p><p>Run this command on your Mac:</p><pre>find ~/Library/Android/sdk/build-tools -name zipalign</pre><p>You’ll get a path like:</p><pre>/Users/yourname/Library/Android/sdk/build-tools/34.0.0/zipalign</pre><p><strong>Step 2: Run the Check</strong></p><p>Assuming your .aab is on the Desktop:</p><pre>/Users/yourname/Library/Android/sdk/build-tools/34.0.0/zipalign -c -v 16384 ~/Desktop/app-release.aab</pre><p>If successful, you’ll see:</p><pre>Verification successful</pre><p>🎉 You’re done!</p><h3>🕵️ Advanced Debugging: Finding the Misaligned .so File</h3><p>Sometimes, you’ll see a detailed message like this from Play Console:</p><pre>Libraries that do not support 16 KB:<br>base/lib/x86_64/libtensorflowlite_jni.so<br>base/lib/x86_64/librive-android.so</pre><p>These are the native libraries that still use <strong>4 KB alignment</strong> (0x1000).</p><h3>🔍 Check Alignment Yourself</h3><p>If you want to confirm which .so file is the culprit, you can inspect it directly.</p><p>Install GNU binutils on macOS:</p><pre>brew install binutils</pre><p>Then run :</p><pre>/opt/homebrew/opt/binutils/bin/greadelf -l path/to/libtensorflowlite_jni.so</pre><p>Look for the Align column under LOAD sections:</p><p>0x1000 -&gt; ❌ 4 KB → Misaligned</p><p>0x4000 -&gt; ✅ 16 KB → Correct</p><p>If you see 0x1000, that’s the cause of your Play Store warning.</p><h3>💡 When the Issue Comes from a Third-Party SDK</h3><p>Sometimes, the misaligned .so file isn’t yours — it’s part of a dependency.</p><p>Example:<br> libtensorflowlite_jni.so might come from <strong>Sumsub SDK</strong> or <strong>ML Kit</strong>.</p><h3>What You Can Do :</h3><p><strong>Update the library</strong><br> Always use the latest version. For example:</p><p><strong>Contact SDK Support</strong><br> If the vendor claims it’s fixed but you still see 4 KB alignment, report it — the new build might not yet be published.</p><p><strong>Temporarily exclude x86/x86_64 ABIs</strong><br> If the issue is only with x86 (emulator builds), you can skip those architectures:</p><pre>android {<br>    defaultConfig {<br>        ndk {<br>            abiFilters &quot;armeabi-v7a&quot;, &quot;arm64-v8a&quot; // Exclude x86 variants<br>        }<br>    }<br>}</pre><p>✅ This removes the warning temporarily without affecting real Android devices.</p><h3>🚀 Final Step: Upload to Play Console</h3><p>Once your .aab passes verification and you’ve confirmed 16 KB alignment:</p><ul><li>Upload it to <strong>Play Console</strong></li><li>The warning should disappear</li></ul><h3>🔁 Bonus: Add zipalign to PATH</h3><p>Add this to your ~/.zshrc:</p><pre>export PATH=&quot;$PATH:/Users/yourname/Library/Android/sdk/build-tools/34.0.0&quot;</pre><p>Reload your shell:</p><pre>source ~/.zshrc</pre><p>This warning isn’t harmful to your app — but fixing it ensures your users get <strong>faster startups</strong> and <strong>more efficient memory usage</strong> on modern Android devices.</p><p>If you’re using libraries like <strong>TensorFlow Lite</strong>, <strong>Rive</strong>, or <strong>Sumsub SDK</strong>, watch for updates — proper 16 KB alignment is gradually becoming standard.</p><p>Thank you for taking the time to read this article. If you found the information valuable, please consider giving it a clap or sharing it with others who might benefit from it.</p><p><em>Any </em><strong><em>Suggestions</em></strong><em> are welcome. If you need any </em><strong><em>help</em></strong><em> or have questions for Code Contact US. You can follow us on </em><a href="https://www.linkedin.com/showcase/99983594/admin/feed/posts"><strong><em>LinkedIn</em></strong></a><strong><em> </em></strong>f<em>or more updates </em>🔔</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8cea8119df3c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mobile-innovation-network/fixing-the-play-store-warning-recompile-your-app-with-16-kb-native-library-alignment-8cea8119df3c">📦 Fixing the Play Store Warning: “Recompile Your App with 16 KB Native Library Alignment”</a> was originally published in <a href="https://medium.com/mobile-innovation-network">Mobile Innovation Network</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Gradle Dependency Configurations]]></title>
            <link>https://medium.com/mobile-innovation-network/android-gradle-dependency-configurations-4c93af190994?source=rss-b3f04ce96171------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c93af190994</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[configuration]]></category>
            <category><![CDATA[gradle]]></category>
            <dc:creator><![CDATA[Mayur Waghmare]]></dc:creator>
            <pubDate>Tue, 24 Jun 2025 05:01:13 GMT</pubDate>
            <atom:updated>2025-10-06T11:58:01.444Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lom4hrBwXsm4SQ-zp1oI1Q.png" /></figure><p>Gradle is the build system for Android projects, and managing dependencies efficiently is crucial for project organization and performance. In this article, we will explore different Gradle dependency configurations, their differences, and best practices for using them effectively.</p><h3>🚀 Key Dependency Configurations</h3><p>Here are the main Gradle dependency configurations in Android development:</p><p><strong>1. implementation<br></strong>This is the most commonly used configuration. Dependencies declared with implementation are available only to the current module and not to other modules that depend on it.</p><blockquote>Use this when you want to include a library in your module but do not want to expose it to other modules that depend on your module.</blockquote><pre>dependencies {<br>    implementation &#39;androidx.core:core-ktx:1.9.0&#39;<br>}</pre><p><strong>2. api<br></strong>The api configuration is similar to <strong>implementation</strong>, but it allows <strong>transitive dependencies</strong>. This means if <strong>Module A</strong> depends on <strong>Module B</strong> using api, then <strong>Module C </strong>(which depends on Module A) will also have access to the dependencies of Module B.</p><blockquote>Use api when you want to expose a dependency to modules that depend on your module.</blockquote><pre>dependencies {<br>    api &#39;com.google.code.gson:gson:2.8.9&#39;<br>}</pre><p><strong>3. compileOnly<br></strong>Dependencies added with compileOnly are only available at compile time and are not included in the final APK.</p><blockquote>Use this when you need a library only for compilation, such as annotations or code-generation tools.</blockquote><pre>dependencies {<br>    compileOnly &#39;org.projectlombok:lombok:1.18.22&#39;<br>}</pre><p><strong>4. runtimeOnly<br></strong>Dependencies declared as runtimeOnly are included in the final APK but are not available at compile time.</p><blockquote>Use this when a library is required only at runtime, such as database drivers.</blockquote><pre>dependencies {<br>    runtimeOnly &#39;mysql:mysql-connector-java:8.0.28&#39;<br>}</pre><p><strong>5. testImplementation<br></strong>This configuration is used for dependencies required only in local unit tests.</p><blockquote>Use testImplementation for unit testing dependencies.</blockquote><pre>dependencies {<br>    testImplementation &#39;junit:junit:4.13.2&#39;<br>}</pre><p><strong>6. androidTestImplementation<br></strong>This configuration is used for dependencies required in Android instrumented tests.</p><blockquote>Use this when you need dependencies for tests that run on an actual Android device or emulator.</blockquote><pre>dependencies {<br>    androidTestImplementation &#39;androidx.test.ext:junit:1.1.3&#39;<br>}</pre><p><strong>7. annotationProcessor<br></strong>This configuration is used for annotation processors like Dagger, Room, and Glide.</p><blockquote>Use this when adding libraries that generate code at compile time.</blockquote><pre>dependencies {<br>    annotationProcessor &#39;com.google.dagger:dagger-compiler:2.40&#39;<br>}</pre><p><strong>8. kapt<br></strong>The kapt (Kotlin Annotation Processing Tool) configuration is the Kotlin equivalent of annotationProcessor.</p><blockquote>Use this for annotation processors in Kotlin projects.</blockquote><pre>dependencies {<br>    kapt &#39;com.google.dagger:dagger-compiler:2.40&#39;<br>}</pre><h4>🎯 Differences Between Dependency Configurations</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*dvAKEDn4DyfBH2tq9k8Cpw.avif" /></figure><h4>Best Practices for Dependency Management</h4><p>✅ Prefer <strong>implementation</strong> over <strong>api</strong> to avoid unnecessary dependency exposure.</p><p>✅ Use <strong>compileOnly</strong> for annotation processors or compile-time dependencies.</p><p>✅ Keep dependencies up to date to avoid security vulnerabilities.</p><p>✅ Use <strong>testImplementation</strong> and <strong>androidTestImplementation</strong> to separate test dependencies from production code.</p><p>✅ Use <strong>annotationProcessor</strong> for Java projects and <strong>kapt</strong> for Kotlin projects when using annotation processing.</p><p>Thank you for taking the time to read this article. If you found the information valuable, please consider giving it a clap or sharing it with others who might benefit from it.</p><p><em>Any </em><strong><em>Suggestions</em></strong><em> are welcome. If you need any </em><strong><em>help</em></strong><em> or have questions for Code Contact US. You can follow us on </em><a href="https://www.linkedin.com/showcase/99983594/admin/feed/posts"><strong><em>LinkedIn</em></strong></a><strong><em> </em></strong>f<em>or more updates </em>🔔</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c93af190994" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mobile-innovation-network/android-gradle-dependency-configurations-4c93af190994">Android Gradle Dependency Configurations</a> was originally published in <a href="https://medium.com/mobile-innovation-network">Mobile Innovation Network</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Widgets in Android — The Simple Guide]]></title>
            <link>https://medium.com/mobile-innovation-network/widgets-in-android-the-simple-guide-c5bb95853d6b?source=rss-b3f04ce96171------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5bb95853d6b</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[compose]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[widget]]></category>
            <dc:creator><![CDATA[Mayur Waghmare]]></dc:creator>
            <pubDate>Mon, 09 Jun 2025 07:50:23 GMT</pubDate>
            <atom:updated>2025-10-07T09:43:43.364Z</atom:updated>
            <content:encoded><![CDATA[<h3>🧩 Widgets in Android — The Simple Guide</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iih1KyDohZMWM-3LTr2cEA.jpeg" /></figure><p>Widgets are one of the coolest features in Android. They let users interact with your app right from the <strong>home screen</strong> — without even opening it!</p><p>In this article, let’s explore:</p><ul><li>What are Android Widgets?</li><li>How to create a <strong>traditional XML-based widget</strong></li><li>How to create a <strong>Glance widget</strong> using Jetpack Glance</li><li>When to use which</li></ul><p>Let’s dive in!</p><h3>🤔 What is an Android Widget?</h3><p>An Android widget is a <strong>small UI component</strong> that sits on the home screen. It can show information or even let the user interact, like a music player or a weather update.</p><p>There are two common types:</p><ul><li><strong>Traditional Widgets</strong>: Built using XML and RemoteViews</li><li><strong>Glance Widgets</strong>: Built using Jetpack Glance (similar to Jetpack Compose)</li></ul><h3>🧱 Traditional Widget using XML</h3><p>These widgets are created using XML layouts and RemoteViews.</p><h4>Step 1: Create the Widget Layout</h4><pre>&lt;!-- res/layout/widget_layout.xml --&gt;<br>&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:orientation=&quot;vertical&quot;<br>    android:background=&quot;@android:color/white&quot;<br>    android:padding=&quot;8dp&quot;<br>    android:layout_width=&quot;wrap_content&quot;<br>    android:layout_height=&quot;wrap_content&quot;&gt;<br><br>    &lt;TextView<br>        android:id=&quot;@+id/widgetText&quot;<br>        android:text=&quot;Hello Widget!&quot;<br>        android:textSize=&quot;16sp&quot;<br>        android:textColor=&quot;@android:color/black&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot; /&gt;<br>&lt;/LinearLayout&gt;</pre><h4>Step 2: Create the AppWidgetProvider Class</h4><pre>class MyWidget : AppWidgetProvider() {<br>    override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {<br>        for (id in appWidgetIds) {<br>            val views = RemoteViews(context.packageName, R.layout.widget_layout)<br>            views.setTextViewText(R.id.widgetText, &quot;Updated Widget!&quot;)<br>            appWidgetManager.updateAppWidget(id, views)<br>        }<br>    }<br>}</pre><h4>Step 3: Define the Widget in XML</h4><pre>&lt;!-- res/xml/my_widget_info.xml --&gt;<br>&lt;appwidget-provider xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:minWidth=&quot;150dp&quot;<br>    android:minHeight=&quot;60dp&quot;<br>    android:updatePeriodMillis=&quot;1800000&quot;<br>    android:initialLayout=&quot;@layout/widget_layout&quot;<br>    android:widgetCategory=&quot;home_screen&quot; /&gt;</pre><h4>Step 4: Add to the Manifest</h4><pre>&lt;receiver android:name=&quot;.MyWidget&quot; android:exported=&quot;true&quot;&gt;<br>    &lt;intent-filter&gt;<br>        &lt;action android:name=&quot;android.appwidget.action.APPWIDGET_UPDATE&quot; /&gt;<br>    &lt;/intent-filter&gt;<br>    &lt;meta-data<br>        android:name=&quot;android.appwidget.provider&quot;<br>        android:resource=&quot;@xml/my_widget_info&quot; /&gt;<br>&lt;/receiver&gt;</pre><p>✅ That’s it! You now have a basic traditional widget.</p><h3>⚡ Jetpack Glance Widgets (Modern Way)</h3><p>Glance is a <strong>Jetpack library</strong> that lets you build widgets using a <strong>declarative Compose-style</strong>.</p><h4>Step 1: Add Glance Dependencies</h4><p>In your build.gradle:</p><pre>dependencies {<br>    implementation(&quot;androidx.glance:glance-appwidget:1.0.0&quot;)<br>}</pre><h4>Step 2: Create the Glance Widget</h4><pre>class MyGlanceWidget : GlanceAppWidget() {<br>    @Composable<br>    override fun Content() {<br>        Box(<br>            modifier = GlanceModifier.fillMaxSize().padding(16.dp),<br>            contentAlignment = Alignment.Center<br>        ) {<br>            Text(text = &quot;Hello Glance Widget!&quot;)<br>        }<br>    }<br>}</pre><h4>Step 3: Add the Receiver</h4><pre>class MyGlanceWidgetReceiver : GlanceAppWidgetReceiver() {<br>    override val glanceAppWidget: GlanceAppWidget = MyGlanceWidget()<br>}</pre><h4>Step 4: Register in Manifest</h4><pre>&lt;receiver<br>    android:name=&quot;.MyGlanceWidgetReceiver&quot;<br>    android:exported=&quot;true&quot;&gt;<br>    &lt;intent-filter&gt;<br>        &lt;action android:name=&quot;android.appwidget.action.APPWIDGET_UPDATE&quot; /&gt;<br>    &lt;/intent-filter&gt;<br>    &lt;meta-data<br>        android:name=&quot;android.appwidget.provider&quot;<br>        android:resource=&quot;@xml/glance_widget_info&quot; /&gt;<br>&lt;/receiver&gt;</pre><h4>Step 5: Add Widget XML Info</h4><pre>&lt;!-- res/xml/glance_widget_info.xml --&gt;<br>&lt;appwidget-provider xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:minWidth=&quot;150dp&quot;<br>    android:minHeight=&quot;60dp&quot;<br>    android:updatePeriodMillis=&quot;1800000&quot;<br>    android:widgetCategory=&quot;home_screen&quot; /&gt;</pre><p>🎉 Done! You now have a modern widget using Glance and Compose-style UI!</p><h3>👆 User Interaction in Glance Widgets</h3><p>Glance simplifies handling user interaction via the Action classes.You can apply an Action to any component with the <a href="https://developer.android.com/reference/kotlin/androidx/glance/GlanceModifier#(androidx.glance.GlanceModifier).clickable(androidx.glance.action.Action)">GlanceModifier.clickable</a> method.</p><p>In native RemoteViews, this is done via PendingIntents.</p><p>The following actions are described on this page:</p><ul><li><a href="https://developer.android.com/develop/ui/compose/glance/user-interaction#launch-activity">Launch an activity</a></li><li><a href="https://developer.android.com/develop/ui/compose/glance/user-interaction#launch-service">Launch a service</a></li><li><a href="https://developer.android.com/develop/ui/compose/glance/user-interaction#send-broadcast">Send a broadcast event</a></li><li><a href="https://developer.android.com/develop/ui/compose/glance/user-interaction#run-actioncallback">Run callback</a></li></ul><h4>🔹 Launch an Activity</h4><p>To launch an activity on user interaction, provide the <a href="https://developer.android.com/reference/kotlin/androidx/glance/appwidget/action/package-summary#actionStartActivity(android.content.Intent,%20androidx.glance.action.ActionParameters))(..">actionStartActivity</a></p><pre>Button(<br>    text = &quot;Open App&quot;,<br>    onClick = actionStartActivity&lt;MainActivity&gt;()<br>)</pre><h4>🔹 Launch a Service or Send a Broadcast</h4><pre>// Start a Service<br>@Composable<br>fun MyButton() {<br>    // ..<br>    Button(<br>        text = &quot;Sync&quot;,<br>        onClick = actionStartService&lt;SyncService&gt;(<br>            isForegroundService = true // define how the service is launched<br>        )<br>    )<br>}<br><br>// Send Broadcast Event<br>@Composable<br>fun MyButton() {<br>    // ..<br>    Button(<br>        text = &quot;Send&quot;,<br>        onClick = actionSendBroadcast&lt;MyReceiver&gt;()<br>    )<br>}</pre><h4>🔹 Run a Callback</h4><p>To perform background operations like refreshing data without opening the app:</p><pre>class RefreshAction : ActionCallback {<br>    override suspend fun onAction(context: Context, glanceId: GlanceId, parameters: ActionParameters) {<br>        // Handle background task such as refreshing the widget<br>        MyAppWidget().update(context, glanceId)<br>    }<br>}<br><br>Button(<br>    text = &quot;Refresh&quot;,<br>    onClick = actionRunCallback&lt;RefreshAction&gt;()<br>)</pre><h3>Provide parameters to actions</h3><p>To provide additional information to an action, use the <a href="https://developer.android.com/reference/kotlin/androidx/glance/action/ActionParameters">ActionParameters</a> API to create a typed key-value pair. For example, to define the clicked destination:</p><pre>// Define Key<br>private val destinationKey = ActionParameters.Key&lt;String&gt;(<br>    NavigationActivity.KEY_DESTINATION<br>)<br><br>// Attach Value to the Defined Key i.e destinationKey<br>Button(<br>    text = &quot;Home&quot;,<br>    onClick = actionStartActivity&lt;NavigationActivity&gt;(<br>        actionParametersOf(destinationKey to &quot;home&quot;)<br>    )<br>)<br>Button(<br>    text = &quot;Work&quot;,<br>    onClick = actionStartActivity&lt;NavigationActivity&gt;(<br>        actionParametersOf(destinationKey to &quot;work&quot;)<br>    )<br>)<br><br><br>// Then in the target activity get the values<br>override fun onCreate(savedInstanceState: Bundle?) {<br>    super.onCreate(savedInstanceState)<br>    val destination = intent.extras?.getString(KEY_DESTINATION) ?: return<br>    // ...<br>}</pre><h3>⚠️ Disadvantages of Glance Widgets</h3><ul><li>❌ <strong>Limited UI components</strong> — Only basic views are supported.</li><li>🚫 <strong>Not full Compose</strong> — Can’t use all Compose features.</li><li>📐 <strong>Restricted layouts</strong> — Less flexibility than XML.</li><li>🧓 <strong>No support for API &lt; 23</strong> — Won’t work on very old devices.</li><li>🐛 <strong>Still evolving</strong> — Missing features, less community support.</li><li>🔄 <strong>Manual updates needed</strong> — Doesn’t auto-refresh often.</li></ul><h3>🔍 Traditional vs Glance Widgets — Which One?</h3><p>✅ Use Glance Widgets if:</p><ul><li>Your app targets <strong>API 23+ (Android 6.0+)</strong></li><li>You’re using <strong>Jetpack Compose</strong> in your app already</li><li>You need a <strong>simple, modern UI</strong></li><li>You prefer <strong>declarative code</strong></li><li>You’re okay with some <strong>limitations</strong> in layout and components</li></ul><p>✅ Use Traditional Widgets if:</p><ul><li>You need to support <strong>older Android versions</strong></li><li>Your widget requires <strong>complex UI</strong> or <strong>custom layouts</strong></li><li>You want <strong>maximum control</strong> over layout and behavior</li><li>You’re working on a <strong>legacy app</strong> with existing XML infrastructure</li><li>You need features not yet available in <strong>Glance</strong></li></ul><h3>📝 Final Thought</h3><p>While Glance is a powerful and modern approach, it’s still <strong>not a complete replacement</strong> for traditional widgets — yet. If you need full control, extensive UI elements, or support for older devices, keep using traditional widgets or combine both approaches strategically.</p><p><strong>Try it out</strong> and give your app some home screen power! 🚀</p><blockquote><em>Checkout the complete code on Github:</em></blockquote><p><a href="https://github.com/mayurr1512/AndroidWidgets">https://github.com/mayurr1512/AndroidWidgets</a></p><p>If you found this helpful, follow us for such more Android tips &amp; tricks! 💡</p><p><em>Any </em><strong><em>Suggestions</em></strong><em> are welcome. If you need any </em><strong><em>help</em></strong><em> or have questions for Code Contact US. You can follow us on </em><a href="https://www.linkedin.com/showcase/99983594/admin/feed/posts"><strong><em>LinkedIn</em></strong></a><strong><em> </em></strong>f<em>or more updates </em>🔔</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5bb95853d6b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mobile-innovation-network/widgets-in-android-the-simple-guide-c5bb95853d6b">🧩 Widgets in Android — The Simple Guide</a> was originally published in <a href="https://medium.com/mobile-innovation-network">Mobile Innovation Network</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Shortcuts Made Easy]]></title>
            <link>https://medium.com/mobile-innovation-network/android-shortcuts-made-easy-9ae7352ad969?source=rss-b3f04ce96171------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ae7352ad969</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[shortcuts]]></category>
            <category><![CDATA[android-shortcut]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[compose]]></category>
            <dc:creator><![CDATA[Mayur Waghmare]]></dc:creator>
            <pubDate>Mon, 02 Jun 2025 03:36:26 GMT</pubDate>
            <atom:updated>2025-09-22T07:16:26.376Z</atom:updated>
            <content:encoded><![CDATA[<h3>Have you ever wished your users could just skip all the screen-hopping and go straight to the juicy part of your app?</h3><p>Well, say hello to <strong>Android Shortcuts</strong> — Android’s way of saying, <em>“Let me help you help your users do less.”</em></p><p>Whether you’re a developer trying to boost app engagement or just want to add some magic to your home screen, this guide will walk you through shortcuts in Android the fun, easy way. 🪄</p><h3>👀 Wait, What Do Shortcuts Even Look Like?</h3><p>Let’s start with some eye candy 🍭. Here’s how some popular apps use shortcuts:</p><h3>📸 WhatsApp</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FkBz_W0dJDltKeujhcVlUQ.png" /></figure><blockquote><em>Tap-and-hold on the app icon and boom — start a new chat, open your camera, or talk to your favourite person (you know who 🥰).</em></blockquote><h3>📸 YouTube</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N_0VsS0ZV8RzWjA1KleWZA.png" /></figure><blockquote><em>YouTube’s shortcut game is on point — you can jump directly to Subscriptions, Search, or Trending faster than you can say “algorithm.”</em></blockquote><h3>🔍 What Are Android Shortcuts?</h3><p>Shortcuts in Android allow users to quickly launch a specific activity or feature of your app directly from the launcher.</p><p>Think of it like this:</p><ul><li><strong>Without shortcuts</strong>: Open app → Navigate through 2–3 screens → Reach destination.</li><li><strong>With shortcuts</strong>: <em>BAM!</em> You’re there.</li></ul><p>And the best part? There are different flavors!</p><h3>📱 Types of Shortcuts</h3><ol><li><strong>Static Shortcuts</strong> — Declared in XML. Good for stuff that rarely changes.</li><li><strong>Dynamic Shortcuts</strong> — Created at runtime. Great for context-specific actions.</li><li><strong>Pinned Shortcuts</strong> — Users manually pin them to their home screen.</li></ol><h3>✨ Create a Static Shortcut</h3><p>Here’s your shortcut XML file:</p><pre>&lt;shortcuts xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;<br>    &lt;shortcut<br>        android:shortcutId=&quot;open_profile&quot;<br>        android:enabled=&quot;true&quot;<br>        android:icon=&quot;@drawable/ic_profile&quot;<br>        android:shortcutShortLabel=&quot;My Profile&quot;<br>        android:shortcutLongLabel=&quot;Open your profile&quot;&gt;<br>        <br>        &lt;intent<br>            android:action=&quot;android.intent.action.VIEW&quot;<br>            android:targetPackage=&quot;com.example&quot;<br>            android:targetClass=&quot;com.example.ProfileActivity&quot; /&gt;<br>    &lt;/shortcut&gt;<br>&lt;/shortcuts&gt;</pre><p>Now, in your app’s AndroidManifest.xml file, find the activity whose intent filters are set to the <strong>android.intent.action.MAIN</strong> action and the <strong>android.intent.category.LAUNCHER</strong> category.</p><pre>&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>            package=&quot;com.example.myapplication&quot;&gt;<br>  &lt;application ... &gt;<br>    &lt;activity android:name=&quot;Main&quot;&gt;<br>      &lt;intent-filter&gt;<br>        &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;<br>        &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;<br>      &lt;/intent-filter&gt;<br>      <br>      &lt;meta-data android:name=&quot;android.app.shortcuts&quot;<br>                 android:resource=&quot;@xml/shortcuts&quot; /&gt; <br>    &lt;/activity&gt;<br>  &lt;/application&gt;<br>&lt;/manifest&gt;</pre><blockquote><em>Boom. You now have a static shortcut. Easy peasy. 😎</em></blockquote><p>When defining a static shortcut in XML, only two attributes are required. Here’s a quick breakdown:</p><ul><li><strong>android:shortcutId</strong> – A unique string (not a resource) to identify the shortcut in code.</li><li><strong>android:shortcutShortLabel</strong> – A short label (max ~10 chars). Must be a string resource like @string/shortcut_short_label.</li></ul><blockquote><strong>Optional attributes:</strong></blockquote><ul><li><strong>android:shortcutLongLabel</strong> – A longer label (max ~25 chars), shown when space allows. Use a string resource.</li><li><strong>android:shortcutDisabledMessage</strong> – Message shown when shortcut is disabled. Use only if enabled=false.</li><li><strong>android:enabled</strong> – Set to false to disable the shortcut. Default is true.</li><li><strong>android:icon</strong> – Icon shown for the shortcut. Use adaptive icons if possible.</li></ul><h3>🧙‍♂️ Add Dynamic Shortcuts (with runtime spice)</h3><pre>val shortcut = ShortcutInfoCompat.Builder(context, &quot;id_1&quot;)<br>    .setShortLabel(&quot;Grocery List 🛒&quot;)<br>    .setLongLabel(&quot;Open your grocery list&quot;)<br>    .setIcon(IconCompat.createWithResource(context, R.drawable.ic_note))<br>    .setIntent(Intent(context, NoteDetailActivity::class.java).apply {<br>        action = Intent.ACTION_VIEW<br>        putExtra(&quot;note_id&quot;, 123)<br>    })<br>    .build()<br><br>ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)</pre><blockquote><em>Perfect for note apps, recent chats, or launching your favourite cat GIF directly. 🐱</em></blockquote><h3>📌 Want It Pinned? Here You Go</h3><pre>val shortcutManager = getSystemService(ShortcutManager::class.java)<br>if (shortcutManager?.isRequestPinShortcutSupported == true) {<br>    val pinShortcutInfo = ShortcutInfo.Builder(applicationContext, &quot;settings&quot;)<br>        .setShortLabel(&quot;Settings ⚙️&quot;)<br>        .setIcon(Icon.createWithResource(applicationContext, R.drawable.img_buy_crypto))<br>        .setIntent(Intent(applicationContext, SettingsActivity::class.java).apply {<br>            action = Intent.ACTION_VIEW<br>        })<br>        .build()<br><br>    val pinnedShortcutCallbackIntent = shortcutManager.createShortcutResultIntent(pinShortcutInfo)<br><br>    val successCallback = PendingIntent.getBroadcast(<br>        applicationContext, 0, pinnedShortcutCallbackIntent, PendingIntent.FLAG_IMMUTABLE<br>    )<br><br>    shortcutManager.requestPinShortcut(pinShortcutInfo, successCallback.intentSender)<br>}</pre><blockquote><em>Users get full control. You give them superpowers. Win-win. 🦸</em></blockquote><h3>⚠️ Common Mistakes</h3><ul><li>❌ Missing &lt;meta-data&gt; in manifest</li><li>❌ enabled=&quot;false&quot; (or missing entirely)</li><li>❌ Ignoring the max number of dynamic shortcuts (usually 4–5)</li></ul><blockquote><em>Test thoroughly, especially across Android versions.</em></blockquote><h3>🔚 That’s a Wrap</h3><p>With Android Shortcuts, you can:</p><ul><li>Make your app feel fast and smart 🚀</li><li>Help users skip unnecessary taps 🕹️</li><li>Delight your future self with features you’ll forget you added 👏</li></ul><p>So go ahead — create, pin, and dynamically add your way to shortcut greatness.</p><blockquote><em>Checkout the complete code on Github:</em></blockquote><p><a href="https://github.com/mayurr1512/Android-Shortcuts">https://github.com/mayurr1512/Android-Shortcuts</a></p><p><em>Any </em><strong><em>Suggestions</em></strong><em> are welcome. If you need any </em><strong><em>help</em></strong><em> or have questions for Code Contact US. You can follow us on </em><a href="https://www.linkedin.com/showcase/99983594/admin/feed/posts"><strong><em>LinkedIn</em></strong></a><strong><em> </em></strong>f<em>or more updates </em>🔔</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ae7352ad969" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mobile-innovation-network/android-shortcuts-made-easy-9ae7352ad969">Android Shortcuts Made Easy</a> was originally published in <a href="https://medium.com/mobile-innovation-network">Mobile Innovation Network</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mobile App : Data Storage Options]]></title>
            <link>https://medium.com/mobile-innovation-network/mobile-app-data-storage-options-b644f10b5f6f?source=rss-b3f04ce96171------2</link>
            <guid isPermaLink="false">https://medium.com/p/b644f10b5f6f</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[app-store-data]]></category>
            <category><![CDATA[data-storage]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Mayur Waghmare]]></dc:creator>
            <pubDate>Wed, 19 Feb 2025 05:19:17 GMT</pubDate>
            <atom:updated>2025-09-22T07:16:36.782Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mobile App : Data Storage Options</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T0uXKa52oTSQ-37ydtrHJA.jpeg" /></figure><p>🔹 <strong>Data Storage is Essential</strong>: Apps need to store user preferences, files, and datasets.<br>🔹 <strong>Platform-Specific Tools</strong>: Android, iOS, and Flutter offer unique solutions.<br>🔹 <strong>Versatile Options</strong>: From key-value pairs to databases, there’s a method for every need.<br>🔹 <strong>Secure &amp; Efficient</strong>: The right choice ensures performance and security.</p><h3>📱 Android: Data Storage Options</h3><h4><strong>1. SharedPreferences 🗝️</strong></h4><ul><li><strong>Purpose</strong>: Store lightweight key-value pairs (e.g., user preferences or app settings).</li><li><strong>Dependency</strong>: Built into the Android framework.</li></ul><pre>val sharedPreferences = context.getSharedPreferences(&quot;AppPrefs&quot;, Context.MODE_PRIVATE) <br>sharedPreferences.edit()<br>      .putString(&quot;username&quot;, &quot;JohnDoe&quot;)<br>      .apply()</pre><p><strong>Pros</strong>: Easy to use, no external setup.</p><p><strong>Cons</strong>: Not suitable for storing large or complex data.</p><h4><strong>2. DataStore ⚡ <em>(Recommended for modern apps)</em></strong></h4><ul><li><strong>Purpose</strong>: Replaces SharedPreferences with a coroutine-based, safer, and more efficient solution.</li><li><strong>Dependency</strong>:</li></ul><pre>implementation &quot;androidx.datastore:datastore-preferences:1.0.0&quot;</pre><ul><li><strong>Pros</strong>: Asynchronous, avoids data corruption.</li><li><strong>Cons</strong>: Relatively new, limited to small data storage.</li></ul><h4><strong>3. Room Database 🏠 <em>(Abstraction over SQLite)</em></strong></h4><ul><li><strong>Purpose</strong>: Manage structured relational data with type-safe queries.</li><li><strong>Dependency</strong>:</li></ul><pre>implementation(&quot;androidx.room:room-runtime:2.6.1&quot;)<br>ksp(&quot;androidx.room:room-compiler:2.6.1&quot;)</pre><ul><li><strong>Pros</strong>: Reduces boilerplate, supports Kotlin coroutines and Flow.</li><li><strong>Cons</strong>: Requires setup and learning curve.</li></ul><h4><strong>4. EncryptedSharedPreferences 🔒</strong></h4><ul><li><strong>Purpose</strong>: Store sensitive data (e.g., tokens, passwords) securely.</li><li><strong>Dependency</strong>:</li></ul><pre>implementation(&quot;androidx.security:security-crypto:1.1.0-alpha03&quot;)</pre><ul><li><strong>Pros</strong>: Fully encrypted, highly secure.</li><li><strong>Cons</strong>: Limited to small data.</li></ul><h3>🍎 iOS: Data Storage Options</h3><h4><strong>1. UserDefaults 🛠️</strong></h4><ul><li><strong>Purpose</strong>: Store small key-value pairs like app preferences.</li><li><strong>Example</strong>:</li></ul><pre>UserDefaults.standard.set(&quot;JohnDoe&quot;, forKey: &quot;username&quot;)</pre><ul><li><strong>Pros</strong>: Lightweight, simple to use.</li><li><strong>Cons</strong>: Not suitable for complex data or large amounts of data.</li></ul><h4><strong>2. Core Data 📊</strong></h4><ul><li><strong>Purpose</strong>: Manage large datasets with object-relational mapping.</li><li><strong>Dependency</strong>: Built into iOS.</li><li><strong>Pros</strong>: Powerful querying, optimized for Apple devices.</li><li><strong>Cons</strong>: Steep learning curve, unnecessary for simple apps.</li></ul><h4><strong>3. Keychain 🔑 <em>(For Sensitive Data)</em></strong></h4><ul><li><strong>Purpose</strong>: Store sensitive information like passwords securely.</li><li><strong>Dependency</strong>: Use KeychainAccess library for convenience.</li><li><strong>Pros</strong>: Encrypted, highly secure.</li><li><strong>Cons</strong>: Limited storage capacity.</li></ul><h4><strong>4. iCloud ☁️ <em>(Cloud Syncing)</em></strong></h4><ul><li><strong>Purpose</strong>: Store data in the cloud for syncing across devices.</li><li><strong>Dependency</strong>: Use CloudKit.</li><li><strong>Pros</strong>: Enables cross-device sync.</li><li><strong>Cons</strong>: Internet-dependent, complex setup.</li></ul><h3>🛠️ Flutter: Data Storage Options</h3><h4><strong>1. Shared Preferences 🗝️</strong></h4><ul><li><strong>Dependency</strong>:</li></ul><pre>shared_preferences: ^2.0.15</pre><ul><li><strong>Pros</strong>: Simple for small data storage.</li><li><strong>Cons</strong>: Not suitable for structured or large data.</li></ul><h4><strong>2. Hive 🐝 <em>(High-performance NoSQL Database)</em></strong></h4><ul><li><strong>Dependency</strong>:</li></ul><pre>hive_flutter: ^1.1.0</pre><ul><li><strong>Pros</strong>: Fast, lightweight, no boilerplate.</li><li><strong>Cons</strong>: Not ideal for relational data.</li></ul><h4><strong>3. sqflite 📄 <em>(SQLite Plugin)</em></strong></h4><ul><li><strong>Dependency</strong>:</li></ul><pre>sqflite: ^2.0.0+4</pre><ul><li><strong>Pros</strong>: Full SQL support.</li><li><strong>Cons</strong>: Requires manual query writing.</li></ul><h4><strong>4. Secure Storage 🔐 <em>(For Sensitive Data)</em></strong></h4><ul><li><strong>Dependency</strong>:</li></ul><pre>flutter_secure_storage: ^5.0.2</pre><ul><li><strong>Pros</strong>: Encrypted and highly secure.</li><li><strong>Cons</strong>: Limited to small data.</li></ul><h3>💡 When to Use Each Solution?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NXM4BSjGvUZkvQpsEaipHQ.png" /></figure><p>Thank you for taking the time to read this article. If you found the information valuable, please consider giving it a clap or sharing it with others who might benefit from it.</p><p><em>Any </em><strong><em>Suggestions</em></strong><em> are welcome. If you need any </em><strong><em>help</em></strong><em> or have questions for Code Contact US. You can follow us on </em><a href="https://www.linkedin.com/showcase/99983594/admin/feed/posts"><strong><em>LinkedIn</em></strong></a><strong><em> </em></strong>f<em>or more updates </em>🔔</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b644f10b5f6f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mobile-innovation-network/mobile-app-data-storage-options-b644f10b5f6f">Mobile App : Data Storage Options</a> was originally published in <a href="https://medium.com/mobile-innovation-network">Mobile Innovation Network</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding StateFlow, SharedFlow and Channel : Kotlin Coroutines]]></title>
            <link>https://medium.com/mobile-innovation-network/understanding-stateflow-sharedflow-and-channel-kotlin-coroutines-7b91a2432d88?source=rss-b3f04ce96171------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b91a2432d88</guid>
            <category><![CDATA[sharedflow]]></category>
            <category><![CDATA[flow]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-flow]]></category>
            <category><![CDATA[kotlin-stateflow]]></category>
            <dc:creator><![CDATA[Mayur Waghmare]]></dc:creator>
            <pubDate>Tue, 18 Feb 2025 05:12:55 GMT</pubDate>
            <atom:updated>2025-09-22T07:16:46.865Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding StateFlow, SharedFlow and Channel : Kotlin Coroutines</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N87TFdGKYHncYZUrSMbyfw.jpeg" /></figure><h3>❄️ Cold vs. 🔥 Hot Flows</h3><p>Before looking into StateFlow, SharedFlow, and Channel, lets understand the difference between <strong>cold</strong> and <strong>hot</strong> flows:</p><ul><li><strong>Cold Flows</strong>: These start emitting values only when a collector is present. Each collector receives its own independent stream of data.</li><li><strong>Hot Flows</strong>: These emit values regardless of whether there are active collectors. Multiple collectors share the same data stream.</li></ul><h3>1. StateFlow</h3><p>StateFlow is a <strong>hot flow</strong> that emits the latest state value and replays it to new subscribers. It’s designed for state management and works well with Jetpack Compose or LiveData replacements.</p><blockquote><strong>Key Features:</strong></blockquote><ul><li>Always holds a single value.</li><li>Emits the latest value to new collectors.</li><li>Works well for UI state management.</li></ul><blockquote><strong>Syntax:</strong></blockquote><pre>val stateFlow = MutableStateFlow(0)<br>stateFlow.value = 1</pre><pre>lifecycleScope.launch {<br>    stateFlow.collect { value -&gt;<br>        println(value) // Prints 1<br>    }<br>}</pre><blockquote><strong>When to Use:</strong></blockquote><ul><li>Managing <strong>state</strong> in a reactive UI.</li><li>Observing and updating values consistently across multiple collectors.</li></ul><h3>2. SharedFlow</h3><p>SharedFlow is a <strong>hot flow</strong> that emits values to multiple collectors simultaneously. Unlike StateFlow, it doesn’t hold a default value and is suited for <strong>events</strong>.</p><blockquote><strong>Key Features:</strong></blockquote><ul><li>Does not retain a single value.</li><li>Can replay recent emissions to new collectors.</li><li>Suitable for event streams like navigation or UI events.</li></ul><blockquote><strong>Syntax:</strong></blockquote><pre>val sharedFlow = MutableSharedFlow&lt;Int&gt;()<br>lifecycleScope.launch {<br>    sharedFlow.emit(1) // Emit value<br>}<br>lifecycleScope.launch {<br>    sharedFlow.collect { value -&gt;<br>        println(value) // Prints 1<br>    }<br>}</pre><blockquote><strong>When to Use:</strong></blockquote><ul><li>Emitting <strong>one-time events</strong> (e.g., navigation commands, error messages).</li><li>Sharing streams of data with multiple subscribers.</li></ul><h3>3. Channel</h3><p>Channel provides a <strong>FIFO (First In, First Out)</strong> queue for coroutines to send and receive values. Unlike StateFlow and SharedFlow, it’s <strong>cold</strong> and suspends senders or receivers when the queue is full or empty.</p><blockquote><strong>Key Features:</strong></blockquote><ul><li>Provides a buffer for data.</li><li>Can suspend producers or consumers based on buffer capacity.</li><li>Supports both one-to-one and many-to-many communication.</li></ul><blockquote><strong>Syntax:</strong></blockquote><pre>val channel = Channel&lt;Int&gt;()</pre><pre>lifecycleScope.launch {<br>    for(x in 1&lt;=..&lt;=5) {<br>      channel.send(x)<br>    }<br>}</pre><pre>lifecycleScope.launch {<br>    repeat(5) {<br>      val value = channel.receive()<br>      println(value) // Prints value<br>    }<br>}</pre><blockquote><strong>When to Use:</strong></blockquote><ul><li>Implementing <strong>producer-consumer patterns</strong>.</li><li>Managing backpressure and controlling data flow.</li><li>One-to-one or many-to-many coroutine communication.</li></ul><h3>Which One Should You Use?</h3><ul><li><strong>StateFlow</strong>: Use for UI state management where you need to observe and react to the latest value.</li><li><strong>SharedFlow</strong>: Use for event streams, such as navigation or showing error messages.</li><li><strong>Channel</strong>: Use for producer-consumer scenarios and handling backpressure efficiently.</li></ul><p>Thank you for taking the time to read this article. If you found the information valuable, please consider giving it a clap or sharing it with others who might benefit from it.</p><p><em>Any </em><strong><em>Suggestions</em></strong><em> are welcome. If you need any </em><strong><em>help</em></strong><em> or have questions for Code Contact US. You can follow us on </em><a href="https://www.linkedin.com/showcase/99983594/admin/feed/posts"><strong><em>LinkedIn</em></strong></a><strong><em> </em></strong>f<em>or more updates </em>🔔</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b91a2432d88" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mobile-innovation-network/understanding-stateflow-sharedflow-and-channel-kotlin-coroutines-7b91a2432d88">Understanding StateFlow, SharedFlow and Channel : Kotlin Coroutines</a> was originally published in <a href="https://medium.com/mobile-innovation-network">Mobile Innovation Network</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Dependency Injection in Android]]></title>
            <link>https://medium.com/mobile-innovation-network/understanding-dependency-injection-in-android-db55a965b549?source=rss-b3f04ce96171------2</link>
            <guid isPermaLink="false">https://medium.com/p/db55a965b549</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[dependency-management]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <dc:creator><![CDATA[Mayur Waghmare]]></dc:creator>
            <pubDate>Fri, 14 Feb 2025 05:31:24 GMT</pubDate>
            <atom:updated>2025-02-17T11:54:06.853Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*woI3pxxumSYkemFzfre0rQ.jpeg" /></figure><h4><strong>What is Dependency Injection?</strong></h4><p>A technique where one object provides the dependencies (other objects it needs) of another object.</p><p>Instead of creating dependencies within a class, they are passed from the outside.</p><h4><strong>Why Dependency Injection?</strong></h4><p>In Android, activities, fragments, or view models often depend on other classes for tasks like network calls or data persistence.</p><p><strong>Without DI</strong>, dependencies are created inside the class, leading to tight coupling, which makes the code harder to test, extend, or modify.</p><blockquote>Here, Dependency Injection plays a major role :</blockquote><ol><li><strong>Decouples Code</strong>: It separates how objects are created from how they are used.</li><li><strong>Enhances Testability</strong>: You can replace real objects with test ones during testing.</li><li><strong>Improves Scalability</strong>: Makes it easier to manage large codebases with multiple dependencies.</li></ol><h4><strong>Types of Dependency Injection</strong></h4><blockquote>There are three common types of Dependency Injection:</blockquote><ol><li><strong>Constructor Injection</strong>: Dependencies are provided through the constructor of the class.</li><li><strong>Field Injection</strong>: Dependencies are injected directly into fields (usually with the help of a framework).</li><li><strong>Method Injection</strong>: Dependencies are provided via setter or other methods in the class.</li></ol><h3>A Simple Example</h3><h4><strong>- Without Dependency Injection</strong></h4><pre>class MyViewModel(private val repository: Repository) {<br>    fun fetchData() = repository.getData()<br>}<br><br>class Repository {<br>    fun getData() = &quot;Data fetched&quot;<br>}<br><br>class MainActivity : AppCompatActivity() {<br>    private lateinit var viewModel: MyViewModel<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.activity_main)<br><br>        val repository = Repository() // Manual dependency creation<br>        viewModel = MyViewModel(repository) // Manually injecting dependency<br><br>        println(viewModel.fetchData())<br>    }<br>}</pre><blockquote>Here:</blockquote><ol><li>MainActivity creates the Repository.</li><li>It passes it to MyViewModel manually.</li><li>This tight coupling makes testing harder and the code less flexible.</li></ol><h4><strong><em>- With Dependency Injection (Using Hilt)</em></strong></h4><p>Dependency injection frameworks like <strong>Hilt</strong> automate this process. Here’s how it looks:</p><p><strong>1. Add Hilt Dependencies</strong></p><p>In your build.gradle:</p><pre>dependencies {<br>    implementation &quot;com.google.dagger:hilt-android:2.x&quot;<br>    kapt &quot;com.google.dagger:hilt-compiler:2.x&quot;<br>}</pre><p><strong>2. Annotate the Application Class</strong></p><pre>@HiltAndroidApp<br>class MyApp : Application()</pre><p><strong>3. Define Your Dependencies</strong></p><p>Create a module to provide the dependencies:</p><pre>@Module<br>@InstallIn(SingletonComponent::class)<br>object AppModule {<br><br>    @Provides<br>    fun provideRepository(): Repository = Repository()<br>}</pre><p><strong>4. Inject Dependencies into the ViewModel</strong></p><pre>@HiltViewModel<br>class MyViewModel @Inject constructor(private val repository: Repository) : ViewModel() {<br>    fun fetchData() = repository.getData()<br>}</pre><p><strong>5. Inject the ViewModel into the Activity</strong></p><pre>@AndroidEntryPoint<br>class MainActivity : AppCompatActivity() {<br>    private val viewModel: MyViewModel by viewModels()<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        setContentView(R.layout.activity_main)<br><br>        println(viewModel.fetchData())<br>    }<br>}</pre><h3>Key Advantages of Using Hilt</h3><ol><li><strong>No Boilerplate Code</strong>: Hilt takes care of creating and providing dependencies.</li><li><strong>Scalable</strong>: Adding new dependencies becomes seamless.</li><li><strong>Testable</strong>: You can easily mock dependencies for testing.</li><li><strong>Optimized for Android</strong>: Hilt is tailored to work efficiently with Android’s unique lifecycle.</li><li><strong>Automatic Lifecycle Management</strong>: Hilt takes care of the lifecycle of injected objects. For example, it automatically destroys and cleans up objects when an Activity or Fragment is destroyed.</li></ol><p>Thank you for taking the time to read this article. If you found the information valuable, please consider giving it a clap or sharing it with others who might benefit from it.</p><p><em>Any </em><strong><em>Suggestions</em></strong><em> are welcome. If you need any </em><strong><em>help</em></strong><em> or have questions for Code Contact US. You can follow us on </em><a href="https://www.linkedin.com/showcase/99983594/admin/feed/posts"><strong><em>LinkedIn</em></strong></a><strong><em> </em></strong>f<em>or more updates </em>🔔</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db55a965b549" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mobile-innovation-network/understanding-dependency-injection-in-android-db55a965b549">Understanding Dependency Injection in Android</a> was originally published in <a href="https://medium.com/mobile-innovation-network">Mobile Innovation Network</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Memory Leaks in Android]]></title>
            <link>https://medium.com/mobile-innovation-network/understanding-memory-leaks-in-android-7c26054eab61?source=rss-b3f04ce96171------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c26054eab61</guid>
            <category><![CDATA[preventmemoryleak]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-memory-leaks]]></category>
            <category><![CDATA[memory-leak]]></category>
            <dc:creator><![CDATA[Mayur Waghmare]]></dc:creator>
            <pubDate>Thu, 13 Feb 2025 05:17:47 GMT</pubDate>
            <atom:updated>2025-02-17T11:53:56.017Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NhjZpoedoWVwi_qB3tbABA.jpeg" /></figure><h3>What Are Memory Leaks? 🧠</h3><p>A memory leak happens when an app keeps references to <strong>unused</strong> <strong>objects</strong>, blocking the garbage collector from freeing up memory.</p><p>Over time, this extra memory usage can cause out-of-memory errors and crashes.</p><blockquote><strong>Key Characteristics of Memory Leaks:</strong></blockquote><ul><li>Unused objects remain in memory.</li><li>Garbage collector cannot reclaim the memory.</li><li>Gradual increase in memory usage over time.</li></ul><h3>Effects of Memory Leaks 🚨</h3><blockquote>Memory leaks can cause significant performance and stability issues, such as:</blockquote><ul><li><strong>Increased Memory Usage:</strong> Apps consume more memory than required, reducing efficiency.</li><li><strong>Reduced Performance:</strong> Sluggish app behaviour due to insufficient memory for other tasks.</li><li><strong>App Crashes:</strong> Out-of-memory errors can result in crashes, harming the user experience.</li></ul><h3>How to Detect Memory Leaks 🔍</h3><p><strong>1. Android Profiler</strong></p><ul><li>Built into Android Studio.</li><li>Monitors memory usage and identifies retained objects.</li></ul><p><strong>2. LeakCanary</strong></p><ul><li>Open-source library.</li><li>Automatically detects and reports memory leaks.</li></ul><p><strong>3. MAT (Memory Analyzer Tool)</strong></p><ul><li>Eclipse-based tool for analysing heap dumps.</li></ul><blockquote><strong>Steps to Detect:</strong></blockquote><ul><li>Observe memory usage in Android Profiler.</li><li>Capture a heap dump and analyze it.</li><li>Identify retained objects and inspect their references.</li></ul><h3>Major Causes of Memory Leaks in Android 🔗</h3><p><strong>1. Activity/Fragment Leaks</strong></p><ul><li><strong>Cause:</strong> Retaining references to Activities or Fragments in long-lived objects like static fields or background threads.</li></ul><pre>object Singleton {<br>    var activity: Activity? = null<br>}</pre><p><strong>2. Static References</strong></p><ul><li><strong>Cause:</strong> Using static variables to hold references to Views, Contexts, or Activities.</li><li><strong>Fix:</strong> Avoid holding static references to lifecycle-aware components.</li></ul><p><strong>3. Inner Classes</strong></p><ul><li><strong>Cause:</strong> Non-static inner classes hold implicit references to their outer class.</li></ul><pre>class MainActivity : AppCompatActivity() {<br>    private val handler = Handler(Looper.getMainLooper())<br>}</pre><p><strong>4. Listeners and Callbacks</strong></p><ul><li><strong>Cause:</strong> Unregistered listeners or callbacks continue to reference objects.<br><strong>Fix:</strong> Properly unregister listeners during onDestroy().</li></ul><p><strong>5. Bitmaps</strong></p><ul><li><strong>Cause:</strong> Loading large bitmaps without proper recycling.</li><li><strong>Fix:</strong> Use optimized libraries like Glide or Picasso.</li></ul><p><strong>6. WebView</strong></p><ul><li><strong>Cause:</strong> WebView retains memory even after the Activity is destroyed.</li><li><strong>Fix:</strong> Use application context or destroy WebView explicitly.</li></ul><h3>How to Prevent Memory Leaks ✅</h3><p><strong>1. Use WeakReferences</strong></p><ul><li>Holds a reference to an object without preventing garbage collection.</li></ul><pre>val weakActivity = WeakReference(activity)</pre><p><strong>2. Avoid Static References to Context</strong></p><ul><li>Never store Context in static fields or singletons.</li></ul><p><strong>3. Use Lifecycle-Aware Components</strong></p><ul><li>Components like ViewModel and LiveData manage their own lifecycle.</li></ul><p><strong>4. Properly Manage Resources</strong></p><ul><li>Release resources like cursors, files, and database connections when done.</li></ul><p><strong>5. Unregister Listeners and Callbacks</strong></p><ul><li>Always unregister listeners in onDestroy().</li></ul><p><strong>6. Use Memory-Optimized Libraries</strong></p><ul><li>Use libraries like Glide for image handling and ensure proper memory caching.</li></ul><h3>Best Practices for Memory Management 🛠️</h3><ul><li><strong>Enable StrictMode:</strong> Detect accidental memory leaks during development.</li></ul><pre>StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().penaltyLog().build())</pre><ul><li><strong>Minimize Long-Lived Objects:</strong> Avoid retaining references to objects for longer than necessary.</li><li><strong>Optimize Bitmap Usage:</strong> Scale images and use memory-efficient formats.</li></ul><h3>Additional Tips 💡</h3><ul><li>Regularly test memory usage with tools like LeakCanary.</li><li>Leverage Jetpack components like WorkManager and ViewModel for lifecycle-aware tasks.</li><li>Review heap dumps periodically during development.</li></ul><p>Thank you for taking the time to read this article. If you found the information valuable, please consider giving it a clap or sharing it with others who might benefit from it.</p><p><em>Any </em><strong><em>Suggestions</em></strong><em> are welcome. If you need any </em><strong><em>help</em></strong><em> or have questions for Code Contact US. You can follow us on </em><a href="https://www.linkedin.com/showcase/99983594/admin/feed/posts"><strong><em>LinkedIn</em></strong></a><strong><em> </em></strong>f<em>or more updates </em>🔔</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c26054eab61" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mobile-innovation-network/understanding-memory-leaks-in-android-7c26054eab61">Understanding Memory Leaks in Android</a> was originally published in <a href="https://medium.com/mobile-innovation-network">Mobile Innovation Network</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Kotlin Coroutines in Android]]></title>
            <link>https://medium.com/mobile-innovation-network/understanding-kotlin-coroutines-in-android-5a8fc54f63e9?source=rss-b3f04ce96171------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a8fc54f63e9</guid>
            <category><![CDATA[asynchronous-programming]]></category>
            <category><![CDATA[coroutinescope]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-coroutines]]></category>
            <dc:creator><![CDATA[Mayur Waghmare]]></dc:creator>
            <pubDate>Thu, 13 Feb 2025 04:54:07 GMT</pubDate>
            <atom:updated>2025-10-22T09:32:12.868Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0yf1mYTkw0YJtvvxAi6KUw.jpeg" /></figure><p>If you’re an Android developer just starting with Kotlin, you’ve likely heard the term C<strong>oroutines</strong>. They’re a powerful way to write asynchronous code, but the concept seems to be hard to understand.</p><h4><strong>What Are Coroutines?</strong></h4><blockquote><em>The Kotlin team defines coroutines as “</em><strong><em>lightweight threads</em></strong><em>”.</em></blockquote><ul><li>It helps you write asynchronous, non-blocking code in a simple and sequential manner.</li><li>Unlike threads, coroutines are <strong>lightweight, efficient, and designed to simplify concurrent programming.</strong></li></ul><h4><strong>How Coroutines Work?</strong></h4><ul><li>Coroutines are based on <strong>suspension</strong> and <strong>resumption</strong>.</li><li>Instead of blocking a thread while waiting (e.g., for network data), coroutines suspend their execution.</li><li>They free up threads instead of blocking them.</li><li>Threads can do other work while waiting.</li><li>When the result is ready, the coroutine resumes where it left off.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*qOuxntRqIRPJabxQs1HKaw.png" /></figure><h4><strong>Example: Fetching Data from an API</strong></h4><blockquote><em>Let’s say you want to fetch user data from an API and display it:</em></blockquote><p><strong>Without Coroutines (Using Threads):</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*qchWVhf0vqYy_ZqI2AMK_A.png" /></figure><ul><li>Here you manually manage threads.</li><li>You need to ensure that UI updates run on main thread.</li><li>The process is error-prone.</li></ul><h4><strong>With Coroutines:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*gRHTsCMiNU-fTfW8B9FAew.png" /></figure><ul><li>Here, the code is clean and concise</li><li>Easy to follow.</li><li>The coroutines automatically handles thread switching.</li></ul><h4><strong>Coroutine Builders</strong></h4><blockquote>Kotlin provides several coroutine builders to help you get started:</blockquote><p><strong>1. launch:</strong> Launches a coroutine that doesn’t return a result.</p><pre>lifecycleScope.launch {<br>    delay(1000L) // Simulate a delay<br>    println(&quot;Hello from coroutine&quot;)<br>}</pre><p><strong>2. async:</strong> Launches a coroutine that returns a result.</p><pre>lifecycleScope.launch {<br>    val result = async { fetchData() }<br>    println(&quot;Result : ${result.await()}&quot;)<br>}</pre><p><strong>3. runBlocking:</strong> Blocks the current thread while waiting for coroutine completion. Often used in testing.</p><pre>runBlocking {<br>    println(&quot;Starting Coroutine&quot;)<br>    delay(1000L)<br>    println(&quot;Coroutine Finished&quot;)<br>}</pre><h4><strong>Coroutine Scopes</strong></h4><blockquote>Scopes define the lifecycle of coroutines. For Android development, common scopes include:</blockquote><ul><li><strong>GlobalScope:</strong> Lives throughout the app’s lifecycle (avoid overusing).</li><li><strong>lifecycleScope:</strong> Tied to an Activity or Fragment’s lifecycle.</li><li><strong>viewModelScope:</strong> Tied to a ViewModel’s lifecycle.</li></ul><h4><strong>Why Use Coroutines?</strong></h4><ol><li><strong>Simplifies Code:</strong> Write asynchronous code in a sequential style.</li><li><strong>Improves Performance:</strong> Efficiently handles tasks without creating too many threads.</li><li><strong>Reduces Errors:</strong> Avoids pitfalls like callback hell and thread management.</li></ol><p>Thank you for taking the time to read this article. If you found the information valuable, please consider giving it a clap or sharing it with others who might benefit from it.</p><p><em>Any </em><strong><em>Suggestions</em></strong><em> are welcome. If you need any </em><strong><em>help</em></strong><em> or have questions for Code Contact US. You can follow us on </em><a href="https://www.linkedin.com/showcase/99983594/admin/feed/posts"><strong><em>LinkedIn</em></strong></a><strong><em> </em></strong>f<em>or more updates </em>🔔</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a8fc54f63e9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mobile-innovation-network/understanding-kotlin-coroutines-in-android-5a8fc54f63e9">Understanding Kotlin Coroutines in Android</a> was originally published in <a href="https://medium.com/mobile-innovation-network">Mobile Innovation Network</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>