<?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 tanya anand on Medium]]></title>
        <description><![CDATA[Stories by tanya anand on Medium]]></description>
        <link>https://medium.com/@tanya-anand?source=rss-d1cec1d724a6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EYA-JwiXUpU38cKT7cBSug.jpeg</url>
            <title>Stories by tanya anand on Medium</title>
            <link>https://medium.com/@tanya-anand?source=rss-d1cec1d724a6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 07:39:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tanya-anand/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[The Magic of the Android Gradle Plugin]]></title>
            <link>https://tanya-anand.medium.com/the-magic-of-the-android-gradle-plugin-55582405288e?source=rss-d1cec1d724a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/55582405288e</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[android-gradle-plugin]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[tanya anand]]></dc:creator>
            <pubDate>Sat, 15 Jul 2023 08:00:50 GMT</pubDate>
            <atom:updated>2023-07-15T08:00:50.940Z</atom:updated>
            <content:encoded><![CDATA[<p>In the world of Android application development, efficiency and productivity are paramount. Building and maintaining Android apps require a robust and streamlined build process, and that’s where the Android Gradle Plugin steps in. The Android Gradle Plugin, provided by Google, revolutionizes the way developers build, test, and package Android applications. In this blog post, we will dive into the depths of the Android Gradle Plugin and explore how it empowers developers to optimize their workflow and create high-quality Android apps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dcDztdurO6-DlJgN" /></figure><h4>Streamlining the Build Process:</h4><p>The Android Gradle Plugin is built upon the Gradle build system, which is the foundation for building Android apps. It works seamlessly with the Android SDK, making it easier for developers to utilize its capabilities. With the plugin, the build process becomes automated and efficient, reducing the need for manual and error-prone tasks.</p><h4>Resource Processing:</h4><p>The Android Gradle Plugin makes compiling and processing app resources simpler. It smartly merges XML files like layouts, strings, and dimensions into a single binary format. This consolidation optimizes resource usage and enhances app performance. Moreover, the plugin allows for resource shrinking, eliminating unused resources to reduce app size without compromising functionality.</p><h4>Manifest Merging:</h4><p>Handling the AndroidManifest.xml file can be challenging, especially in projects with multiple modules and libraries. The Android Gradle Plugin simplifies this task by automatically merging manifest files. It intelligently combines manifest files from different sources into a single, unified manifest for the entire application. This consolidation ensures consistent configurations and resolves conflicts, making the development process much simpler.</p><h4>Dependency Management:</h4><p>Managing dependencies efficiently is crucial for Android projects. The Android Gradle Plugin makes this process simple by seamlessly integrating with popular dependency management systems like Maven and JCenter. It enables developers to easily declare and resolve project dependencies, whether they are local or remote. The plugin also supports transitive dependency resolution, ensuring that all required libraries are correctly included in the project. This streamlines the dependency management process and saves developers time and effort.</p><h4>Build Variants and Flavors:</h4><p>Creating different versions of an app, like free and paid variants or versions for different languages, can be overwhelming. The Android Gradle Plugin simplifies this by introducing build variants and flavors. These features allow developers to manage multiple versions of their app from a single codebase. It streamlines the build process and makes it easier to create customized versions, saving valuable time and effort. With the plugin, developers can efficiently handle variant-specific configurations and deliver tailored experiences to their users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zI7eGUszYL6ErxVT" /><figcaption>Tailored Apps for you</figcaption></figure><h4>Continuous Integration and Testing:</h4><p>The Android Gradle Plugin offers seamless integration with popular continuous integration (CI) systems like Jenkins or Travis CI. It provides essential tools for automating the build, testing, and deployment process, ensuring that code changes undergo thorough testing before being released. The plugin supports various testing frameworks, including JUnit and Espresso, enabling developers to write comprehensive tests and ensure the stability and quality of their apps. This integration simplifies the CI workflow and helps deliver reliable and high-quality Android applications.</p><h4>Packaging and Signing:</h4><p>Packaging an Android app into an APK file and signing it for distribution is a crucial step in the release process. The Android Gradle Plugin simplifies this process by automating the generation of signed APKs. It takes care of creating different build types, like debug or release builds, and allows developers to configure signing configurations for secure distribution. This functionality ensures that the final app package is ready for deployment without requiring manual intervention. With the Android Gradle Plugin, developers can easily generate signed APKs and distribute their Android apps hassle-free.</p><p>The Android Gradle Plugin: the superhero of Android app development! It’s got a rock-solid build system, ninja-like resource processing, effortless dependency management, and automated packaging and signing. With this powerful sidekick, developers can optimize their workflow, boost productivity, and save the day with top-notch Android apps.</p><blockquote>Thanks for Reading <br>Hoping this can help you in some way.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55582405288e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Operators on Flows]]></title>
            <link>https://tanya-anand.medium.com/operators-on-flows-c2af69efaad7?source=rss-d1cec1d724a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2af69efaad7</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[flow]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[coroutine]]></category>
            <dc:creator><![CDATA[tanya anand]]></dc:creator>
            <pubDate>Mon, 03 Jul 2023 09:39:38 GMT</pubDate>
            <atom:updated>2023-07-03T09:39:38.166Z</atom:updated>
            <content:encoded><![CDATA[<p>Flow is stream of data. Sometime we want to alter the data stream by mapping, merging, filtering, sorting, reducing, splitting, chunking, windowing, sampling, and flat-mapping.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qvaKNNaC88pbuIcz" /></figure><p>For that, there are a series of extension functions on Flow called “operators”.</p><p>We will try to dive into few of popular Flow operators, and understand their use case.</p><h4>debounce()<strong>: Filtering Fast Flows</strong></h4><blockquote><em>val slowFlow = originalFlow.debounce(250)</em></blockquote><p>In debounce(), originalFlow is the input stream and slowFlow is the output stream. Sometimes, you have a Flow that emits too quickly, and you want only those values that have not changed in a while. here debounce acts as a saviour.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r0tw2CsvzUFT9wiN" /></figure><blockquote>Consider the scenario of user input in a text field. Normally, you would want to use that input to filter data from a database or server as the user types. However, since I/O operations can be slow, updating the filter after every keypress may not be ideal. Instead, you would prefer to wait until the user has finished typing, even though there may not be any explicit indication of that. So, the approach is to wait for a significant delay after a keypress before applying the filter. This practice, known as “debouncing” user input, involves disregarding rapid events and focusing on more stable ones.</blockquote><p>When using the debounce() operator, you specify a time period in milliseconds. This operator receives input from the upstream flow and only forwards it downstream if there has been no new input within the specified time period. Additionally, when the upstream flow is closed, the debounce() operator emits the last result it received.</p><p>Let’s go though a small piece of code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e93f25e3fa470ca53fce443fabb9be9/href">https://medium.com/media/0e93f25e3fa470ca53fce443fabb9be9/href</a></iframe><ul><li>The debounce() operator has a delay of 50 milliseconds.</li><li>0 is emitted by the upstream flow and given to debounce().</li><li>After 100 milliseconds, 1 is emitted by the upstream flow.</li><li>debounce() discards the 0 result because it was replaced too quickly.</li><li>After 200 milliseconds, 2 is emitted by the upstream flow.</li><li>debounce() discards the 1 result for the same reason.</li><li>After 50 milliseconds, 3 is emitted by the upstream flow.</li><li>debounce() discards the 2 result.</li><li>Now delay is 400 milliseconds, so debounce() emits 3 since no new result was received within 250 milliseconds.</li><li>4 is emitted by the upstream flow.</li><li>The upstream flow is closed.</li><li>debounce() emits 4 since the upstream flow was closed.</li></ul><p>In simpler terms, debounce() waits for a specific time period before considering a result as valid. It discards results that are replaced too quickly and emits the last result if the upstream flow is closed.</p><blockquote>Thus final output will be <br>3<br>4</blockquote><h4><strong>drop(): Skipping the Start</strong></h4><p>In certain cases, you may want to discard the initial items emitted by a flow. This can occur when you are aware that the first few items are part of a “warmup” phase and the actual meaningful data starts later.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0a252eabe36447dd0ed156783422914/href">https://medium.com/media/a0a252eabe36447dd0ed156783422914/href</a></iframe><p>the first four count of item will be dropped and the out will be</p><blockquote>5, 6, 7, 8, 9, 10</blockquote><h4>dropWhile(): Skip Until You’re Ready</h4><p>The dropWhile() function skips all items in a flow until a provided lambda expression or function returns true. Once that condition is met, the item that triggered the condition and all subsequent items are emitted.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19332df89ce9a481ea238e66d4a377c4/href">https://medium.com/media/19332df89ce9a481ea238e66d4a377c4/href</a></iframe><p>In this scenario, using dropWhile(), we discard items from the flow as long as they are odd. However, as soon as we encounter the first even item, we stop dropping and start emitting all the remaining items as they come.</p><blockquote>2, 3, 4, 5, 6, 7, 8, 9, 10</blockquote><h4>filter(): Take What You Want</h4><p>The filter() function evaluates a provided lambda expression or function on each item emitted by the upstream flow. If the expression evaluates to true for an item, it is passed downstream and emitted.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d016328d9203cd78d772e06d5065acc4/href">https://medium.com/media/d016328d9203cd78d772e06d5065acc4/href</a></iframe><blockquote>3, 6, 9</blockquote><h4>filterIsInstance(): Type Safety, Flow Style</h4><p>By using filterIsInstance(), you can selectively filter emissions from the upstream flow based on their type. Only items that match the specified type will be allowed to pass through and be emitted downstream.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c9a7d371bf859925d1703d5bada32fc/href">https://medium.com/media/5c9a7d371bf859925d1703d5bada32fc/href</a></iframe><p>Only strings will be filtered out.</p><blockquote>note: filterIsInstance() helps when you have a Flow with a common supertype, but you specifically want a Flow of a particular sub-type.</blockquote><h4>filterNot(): Take The Other Stuff Instead</h4><p>The filterNot() function is similar to filter(), but with a negation (!) applied. It only emits items from the upstream flow where the provided lambda expression evaluates to false, whereas filter() looks for items where the expression evaluates to true. In other words, filterNot() selects items that do not satisfy the given condition, while filter() selects items that do satisfy the condition.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7ce821fcfc6cd4fbc0c34cf1fca5d69/href">https://medium.com/media/f7ce821fcfc6cd4fbc0c34cf1fca5d69/href</a></iframe><blockquote>1, 2, 4, 5, 7, 8, 10</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2B5wkM0973zEsoPu" /></figure><p>For more details you can go though book <strong><em>Elements of Kotlin coroutine</em></strong></p><blockquote><em>Happy Learning!<br>Please share any suggestion.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2af69efaad7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inspect Android Network Traffic with Android Studio Flamingo]]></title>
            <link>https://tanya-anand.medium.com/inspect-android-network-traffic-with-android-studio-flamingo-eac6b74f96ae?source=rss-d1cec1d724a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/eac6b74f96ae</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[network]]></category>
            <dc:creator><![CDATA[tanya anand]]></dc:creator>
            <pubDate>Tue, 09 May 2023 04:58:45 GMT</pubDate>
            <atom:updated>2023-05-10T02:17:54.818Z</atom:updated>
            <content:encoded><![CDATA[<h3>Inspect Network Traffic with Android Studio Flamingo</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1jzgnN9pJ1th8RQW" /></figure><p>The Network Inspector is a tool that shows you how your app is using the internet, by displaying a timeline of the data sent and received. With this tool, you can check how your app is transferring data and improve the code to make it work better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CG3MMc7vc6Hm4Kmi" /></figure><p><strong><em>How to open App Inspection &gt; Network Inspector</em></strong></p><p>Method 1</p><ol><li>Look for the navigation bar at the top of the Android Studio interface.</li><li>Click on the “View” menu option located in the navigation bar.</li><li>From the drop-down list that appears, click on “Tool Windows”.</li><li>In the list of Tool Windows options, select “App Inspection”.</li></ol><p>By doing so, you should be able to access the App Inspection feature in Android Studio.</p><p>Method 2</p><p>you can find it in bottom on android studio. Just click on App Inspection and you are there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*d8rUtNSVfCOSXKnwud7_aA.png" /><figcaption>App inpection</figcaption></figure><p>You can select the <em>Network Inspector</em> tab.</p><p>Select the device and app process you want to inspect from the <strong>App Inspection</strong> window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*JkQLhl0B3QZjPq6Y1Y0dYw.png" /></figure><p>The Network Inspector has a timeline at the top that shows events in real-time. If you click and drag on the timeline, you can select a specific portion of it and see more details about the network activity during that time. This allows you to inspect the data being sent and received by your app during that period and analyze it more closely.</p><p>The Network Inspector displays the request and response events as colored sections on the timeline. The yellow section indicates the time period when the request was being sent from your app to the server. The blue section shows the time period when the response was being received by your app from the server. The beginning of the blue section is when the first byte of the response was received, and the end of the blue section is when the final byte of the response was received. This helps you to see the timing and duration of the network activity between your app and the server in a visual way.</p><p>In the tab below timeline, you can select tab for more details.</p><ol><li><strong>Connection view:</strong> The Network Inspector lists files that were sent or received during a selected portion of the timeline, across all of your app’s CPU threads. It provides information about the size, type, status, and transmission duration of each request. You can see a detailed breakdown of the selected timeline showing when each file was sent or received.<br>Also, when you select and item, you will get complete details for that API call.</li><li><strong>Thread view:</strong> The Network Inspector displays network activity on each of your app’s CPU threads, allowing you to see which threads are responsible for each network request.</li><li><strong>Rules view:</strong> Rules help test how your app handles different server responses, including status codes, headers, and message bodies, to ensure that your app works correctly and responds appropriately to errors.</li></ol><blockquote><em>Now, we will try to explore Rules view more.</em></blockquote><h4>Rules View</h4><p>As we came to know, Rules allows us to modify network responses and headers in real-time to simulate different scenarios, which can help us to test and validate your app’s behaviour and improve its performance and reliability. We will learn how we can use this.</p><blockquote>if you’ve used a network proxy before to alter API responses (like Charles), then think of rules as a toned-down, more user-friendly version — like Charles’ little brother who’s just starting out in the proxy game. 😎</blockquote><p>Steps</p><ol><li>Go to Rules tab.</li><li>Give an appropriate name to the new rule you are going to create.</li><li>the “Origin” subsection allows you to specify details about the response source you want to intercept, such as the server’s hostname or path. This ensures that the rule only applies to the intended requests and avoids accidental changes to other requests. Also wildcards are supported. If you keep suppose host name empty, if will become generic.</li><li>The “Response” subsection in the rules configuration allows you to specify how and where to modify the response that you intercepted.</li><li>To enable or disable a rule, you can check or uncheck the “Active” box next to the rule. The order of the rules listed determines the order in which they are applied.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*hKfGZAzpkdIi4SQhYlpSkw.png" /><figcaption>GET request</figcaption></figure><p><em>you can add your rules as shown above for a GET request.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_xgcDT5Mqp0XfiwwQgqhdA.png" /><figcaption>POST request</figcaption></figure><p><em>you can add your rules as shown above for a POST request.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U1xyyZDEYcyQoDo4ZBvkvw.png" /><figcaption>Add query params</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*fbfcGjB5tMPzTuAmrnL6jQ.png" /><figcaption>Request body modification</figcaption></figure><p>when you go Body rules and click on +. you will get a pop up to enter your desired response. you can select checkbox to replace entire body.</p><p>All set to go! now you can run your App. and check the response detail in connection view. Also will get displayed in your App.</p><blockquote>Happy Learning!<br>Please share any suggestion.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eac6b74f96ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrate multiple Flutter modules with Android]]></title>
            <link>https://tanya-anand.medium.com/integrate-multiple-flutter-modules-with-android-82badca744e8?source=rss-d1cec1d724a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/82badca744e8</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[flutter-module]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[add-to-app]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[tanya anand]]></dc:creator>
            <pubDate>Wed, 11 May 2022 05:44:53 GMT</pubDate>
            <atom:updated>2022-05-11T05:47:15.241Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_UL7MSOOEC2PPYao" /></figure><p>When you check the official doc for <a href="https://docs.flutter.dev/development/add-to-app">add 2 app</a>. you will find a limitation as below.</p><blockquote>Packing multiple Flutter libraries into an application isn’t supported.</blockquote><p>But this was our need.</p><p>Stuck here for a while!</p><p>Then, I came across an <a href="https://github.com/flutter/flutter/issues/39707">issue</a> on Github. And, it worked like a charm for us.</p><p>The concept is called <strong><em>Umbrella Approach</em></strong>.</p><p>Where there exists a <strong><em>flutter Guardian module</em></strong>. Which further extends all other flutter modules as packages.</p><p>Our host App will interact with the flutter Guardian module only. Thus just one flutter module is connected with our host App.</p><p>Let&#39;s understand this with an example.</p><p>Suppose we have two flutter modules.</p><ol><li><em>Login</em></li><li><em>Authentication</em></li></ol><p>And, we want to integrate with the android host App.</p><p>Then we will import both as packages to a third flutter module called flutter_umbrella. And, connect <strong><em>flutter_umbrella</em></strong> with the Android host App.</p><p>Let’s understand the implementation with code.</p><p><strong><em>Step 1:</em></strong></p><p>Create a flutter project named <strong><em>flutter_umbrella.</em></strong></p><p><strong><em>Step 2:</em></strong></p><p>Make sure you have kept the android host app, login, and authentication in the same folder.</p><p>Add the path to <strong><em>pubspec.yaml</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ce2ff30f84b16c468f03d028b78ccfa/href">https://medium.com/media/3ce2ff30f84b16c468f03d028b78ccfa/href</a></iframe><p>you can also define a remote path as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5544dec23f11a4c86b3be7b832127ec6/href">https://medium.com/media/5544dec23f11a4c86b3be7b832127ec6/href</a></iframe><blockquote>Use flutter pub get to sync.</blockquote><p><strong><em>Step 3:</em></strong></p><p>Add the following to main.dart</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c40c8174fe64329964871949b6f6bf15/href">https://medium.com/media/c40c8174fe64329964871949b6f6bf15/href</a></iframe><p>The redirection is done on basis of the initial route. <br>To know how to set the initial route. <a href="https://medium.com/@tanya-anand/data-pass-between-flutter-and-android-using-the-method-channel-f0e8f7655fe">please check</a>.</p><p>Now, you are all set up and ready to fly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KDDDHpRwupl1QvHk" /><figcaption>Photo by <a href="https://unsplash.com/es/@kris_ricepees?utm_source=medium&amp;utm_medium=referral">Gary Bendig</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Note: for login and authentication module, while declaring assets like images always mention package name also.</blockquote><p>Hope! This will help you somewhere.</p><p>Please share some love by commenting if you don&#39;t find something in your favor.🧚🏼</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82badca744e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android app size after Flutter module integration]]></title>
            <link>https://tanya-anand.medium.com/android-app-size-after-flutter-module-integration-2cbbe3c655e2?source=rss-d1cec1d724a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cbbe3c655e2</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[app-size]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[add-to-app]]></category>
            <category><![CDATA[flutter-engine]]></category>
            <dc:creator><![CDATA[tanya anand]]></dc:creator>
            <pubDate>Tue, 10 May 2022 09:48:03 GMT</pubDate>
            <atom:updated>2022-05-10T09:52:43.699Z</atom:updated>
            <content:encoded><![CDATA[<p>App size increase is always the biggest concern for a firm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6qPlwyCccCJbpHe-" /></figure><p>The larger the app size, higher the chance of the app getting uninstalled or download failure. Same was for us. So, we decided for a depth Analysis to see what will be actual size after flutter module integration.</p><p>For Integration of Flutter to android. Kindly go through the official site <a href="https://docs.flutter.dev/development/add-to-app">Add Flutter to existing app</a>.</p><p>Flutter has three build modes</p><ol><li>debug</li><li>profile</li><li>release</li></ol><p>where creating a release apk will lead to the most optimized size.</p><p>More on flutter build mode <a href="https://docs.flutter.dev/testing/build-modes">Flutter’s build modes</a></p><p>I have a production android App. Let&#39;s call it AliceApp.</p><p>Now, I have integrated a single-page flutter module into the app. Let&#39;s call it AliceFlutterApp.</p><p>When I created a signed release build of <strong><em>AliceApp</em></strong> it is 14.5 MB.</p><p>When I created a signed release build of <strong><em>AliceFlutterApp</em></strong> it is 30.3 MB.</p><p>Oh! such a huge increase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-3fxmJcwu9Wk_dOx" /></figure><p>When we dig a bit deep by analyzing both apk.</p><p><strong><em>AliceApp.apk</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qZQgmtAh_Yj2Va44_1RH7A.png" /></figure><p><strong><em>AliceFlutterApp.apk</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oRmhP69W4ha3bpoC1pcM4A.png" /></figure><p>What we found,</p><p>An extra lib folder is added and it is contributing 15.7 MB.</p><p>This consists of a flutter engine for 3 supported architectures by flutter.</p><blockquote>The Flutter Engine is a portable runtime for hosting Flutter applications. It implements Flutter’s core libraries, including animation and graphics, file and network I/O, accessibility support, plugin architecture, and a Dart runtime and compile toolchain.</blockquote><p>Since we are generating a combined APK. Thus, we have all 3 flutter engines present with us. But when we upload this as an android app bundle on the play store. While downloading, users will get one of them depending on the phone-supported architecture.</p><p>You can check How big is flutter engine here(<a href="https://docs.flutter.dev/resources/faq#how-big-is-the-flutter-engine">FAQ</a> ).</p><p>The flutter team knows this fact(<a href="https://github.com/flutter/flutter/issues/12456">Too big size for empty APK (engine disk footprint size) · Issue #12456 · flutter/flutter</a> ).</p><p>Wait!🛑</p><p>Just 3 architectures are supported.</p><p><em>Your existing Android app may support architectures such as MIPS or x86. Flutter currently only supports building ahead-of-time (AOT) compiled libraries for x86_64, armeabi-v7a, and arm64-v8a.</em></p><p>This can lead to the loss of customers who are on x86. But still not a huge number.</p><p>· ARMv7: 98.1%</p><p>· Intel x86: 1.7%</p><p>If your app supports armeabi-v7a and arm64-v8a architectures. They cover around 99% of Android devices.</p><p>More on this <a href="http://x86%20architecture%20https//android.stackexchange.com/questions/186334/what-percentage-of-android-devices-runs-on-x86-architecture">% distribution</a></p><p><strong>Experiment result</strong></p><p>When we created a bundle for both apps and distributed it through the play store. The <strong><em>AliceApp</em></strong> size was 14.60 MB.</p><p>The size of the <strong><em>AliceFlutterApp</em></strong> was 27.30 MB.</p><p>An increase of 12.70 MB occurred.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FPyh2YnP4i_pzoK4" /></figure><p>That&#39;s all about the analysis of Android App size increase.</p><p>Hope! this helps you somewhere in your journey.</p><p>Please share some love by commenting if you find something, not in your favor. 🧚🏼</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cbbe3c655e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data pass between Flutter and Android using the Method channel]]></title>
            <link>https://tanya-anand.medium.com/data-pass-between-flutter-and-android-using-the-method-channel-f0e8f7655fe?source=rss-d1cec1d724a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0e8f7655fe</guid>
            <category><![CDATA[android-apps]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[add-to-app]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[tanya anand]]></dc:creator>
            <pubDate>Tue, 10 May 2022 07:00:02 GMT</pubDate>
            <atom:updated>2022-05-10T07:09:11.224Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p4rxE3W4rR1CVd5-" /></figure><p>To create a real-world App, it&#39;s important to pass data to and fro between flutter and the host Android App.</p><p>Method channel is a way for data passing. Now, let&#39;s have a look at how can we do this, with some code examples.</p><p>First and foremost, to use the method channel we have to go with the <a href="https://medium.com/@tanya-anand/open-flutter-module-from-android-app-dd31ba0d130b">cached engine implementation</a> method.</p><p>Let&#39;s do things one by one,</p><p><strong>Step 1:</strong></p><p>Create a method channel for data passing along with cached flutter engine</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c790777b157d9bd0a394671b981bc22e/href">https://medium.com/media/c790777b157d9bd0a394671b981bc22e/href</a></iframe><p>We have created a flutter engine.</p><p><strong><em>setInitialRoute </em></strong>helped in setting the initial route for the flutter engine.</p><p><strong><em>executeDartEntrypoint( DartExecutor.DartEntrypoint.createDefault() ) </em></strong>helped in executing dart code to pre-warm the flutter engine, so that there wont be any delay while launching a flutter activity.</p><p><strong><em>FlutterEngineCache .getInstance() </em></strong>gives an instance of cache where we can store our newly created flutter engine.</p><p><strong><em>MethodChannel( cachedFlutterEngine?.dartExecutor, channelId ) </em></strong>return a method channel, which helps in data passing. every method channel will have a different channelId. which helps in identification. we will understand its use further.</p><p><strong>Step 2:</strong></p><p>Host android app implementation</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27dd033e9be3ff8185e5ae5a9c4fec28/href">https://medium.com/media/27dd033e9be3ff8185e5ae5a9c4fec28/href</a></iframe><p>this will create a method channel instance, which will be used further.</p><p>To send data from Android host App to Flutter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca5fc376b249a6637b02963e2a293f3d/href">https://medium.com/media/ca5fc376b249a6637b02963e2a293f3d/href</a></iframe><p><strong><em>AppConstants.DATA_PASS_METHOD </em></strong>is defined to identify the method name over which the data is passed. this will be used on the flutter end to parse data.</p><p>We can use the same method-channel to receive data from the Flutter module and send some acknowledgment to flutter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1278131330eecb9a0f24f77356cf6ba5/href">https://medium.com/media/1278131330eecb9a0f24f77356cf6ba5/href</a></iframe><p><strong><em>FlutterCallbackMethodNames.TRIGGER_ANALYTICS_EVENT </em></strong>and<strong><em> FlutterCallbackMethodNames.GET_ACCESS_TOKEN</em></strong> are method names over which data is sent from the flutter end and is mapped on the android side to receive respective data and process it.</p><p>In second method <strong><em>FlutterCallbackMethodNames.GET_ACCESS_TOKEN </em></strong>we are also using<strong><em> result.success(AuthUtils.getAuthentication()?.access_token). </em></strong>This is used to send acknowledgment data back to the flutter module. we are using it for refreshing our access token on every API call.</p><p>Now, you can start your flutterActivity</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac94d6fa228ed86387f668ad4c8177ad/href">https://medium.com/media/ac94d6fa228ed86387f668ad4c8177ad/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YrDgVMVrSCI5Hyd9" /></figure><p>That’s all on Android side!!</p><p><strong>Step 3:</strong></p><p>Flutter module implementation</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff12164648119ec2ae6a4be48660d277/href">https://medium.com/media/ff12164648119ec2ae6a4be48660d277/href</a></iframe><p><strong><em>AppConstants.FLUTTER_CHANNEL_ID </em></strong>needs to be the same on both the host and flutter end, to identify the method channel.</p><p>Also, <strong><em>AppConstants.DATA_PASS_METHOD </em></strong>should be the same to identify the method name and parse the actual data.</p><p>Now, let&#39;s see how we can send data from flutter to the android host app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce7b4c4bcecf06663efd823ed8643148/href">https://medium.com/media/ce7b4c4bcecf06663efd823ed8643148/href</a></iframe><p>Inside class <em>AnalyticsHelper</em> we have sent data to android and forget what happened there, same as fire and forget rule.</p><p>But inside tokenRegeneration, we waited for the acknowledgment from the android host side.</p><blockquote>Note: Always make sure the names you are using for mapping is always same on flutter and android side.</blockquote><p>That’s all about Flutter changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XuWD53y2rRchnJwt" /></figure><p>Hope! This helps you somewhere in your journey.</p><p>Please share some love by putting in any comment if you find something, not in your favor. 🧚🏼</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0e8f7655fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Open Flutter module from Android App]]></title>
            <link>https://tanya-anand.medium.com/open-flutter-module-from-android-app-dd31ba0d130b?source=rss-d1cec1d724a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd31ba0d130b</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-engine]]></category>
            <category><![CDATA[method-channel]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[add-to-app]]></category>
            <dc:creator><![CDATA[tanya anand]]></dc:creator>
            <pubDate>Thu, 28 Apr 2022 16:02:07 GMT</pubDate>
            <atom:updated>2022-04-29T09:22:58.791Z</atom:updated>
            <content:encoded><![CDATA[<p>Understand how we can open a flutter module from the host android app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A_-iDxyS7hXt7R1Hpoojbw.png" /></figure><p>Flutter can be added to the android app in three different ways:</p><ol><li>Using <strong>FlutterActivity</strong> (io.flutter.embedding.android.FlutterActivity)</li><li>Using <strong>FlutterFragment</strong> (io.flutter.embedding.android.FlutterFragment)</li><li>Using <strong>FlutterView</strong> (io.flutter.embedding.android.FlutterView)</li></ol><p>Here, we are going to use FlutterActivity to display flutter screens.</p><p>Flutter provides FlutterActivity to display a Flutter experience within an Android app. Like any other activity, FlutterActivity must be registered in your <strong><em>AndroidManifest.xml</em></strong>.</p><h4>Step 1:</h4><p>Add the following XML to your AndroidManifest.xml file under your application tag:</p><pre>&lt;activity<br>  android:name=&quot;io.flutter.embedding.android.FlutterActivity&quot;<br>  android:hardwareAccelerated=&quot;true&quot;<br>  android:windowSoftInputMode=&quot;adjustResize&quot;/&gt;</pre><h4>Step 2:</h4><p>Launch your FlutterActivity, on a click of a button</p><pre>myButton.setOnClickListener {<br>  startActivity(<br>    FlutterActivity<br>      .withNewEngine()<br>      .build(this)<br>  )<br>}</pre><p>The above example assumes that your Dart entry point is called main(), and the initial Flutter route is ‘/’. The Dart entry point can’t be changed using Intent, but the initial route can be changed using Intent.</p><p>Let&#39;s see how we can change the initial route.</p><pre>myButton.setOnClickListener {<br>  startActivity(<br>    FlutterActivity<br>      .withNewEngine()<br>      .initialRoute(&quot;/flutter_route&quot;)<br>      .build(this)<br>  )<br>}</pre><p>Now, our initial route will be ‘/flutter_route’. you can replace it with any desired value you want.</p><p>The use of the <strong><em>withNewEngine()</em></strong> method configures a FlutterActivity that internally creates its own FlutterEngine instance. Also, the FlutterEngine takes some time to start up. which leads to a blank screen for a while.</p><p><em>Ohk! now, what else can be done?</em></p><h3><strong>Alternative approach</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1XhhUOSY2Zf7PHnH" /></figure><p>The alternative approach is to use a <em>pre-warmed</em>, <em>cached FlutterEngine</em>.</p><p>Every FlutterActivity needs its own FlutterEngine by default. Each FlutterEngine has a non-trivial warm-up time. This means that launching a standard FlutterActivity will have a brief delay before becoming visible. To minimize this delay, we need to warm up FlutterEngine before launching FlutterActivity.</p><p>Let&#39;s understand, how we can do this.</p><p>To pre-warm a FlutterEngine, we need to find a location in the app, where we can do this. A good location can be any activity or an Application class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/329e87fd0b238faa9cdb29ce60ecf363/href">https://medium.com/media/329e87fd0b238faa9cdb29ce60ecf363/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b175c3d125a54889f15c6e3b440cdbad/href">https://medium.com/media/b175c3d125a54889f15c6e3b440cdbad/href</a></iframe><blockquote><strong><em>destroyEngineWithActivity</em></strong> will kill your engine every time you kill flutter Activity. You can use or avoid depending on your need.</blockquote><p>Once FlutterEngine is created, every time you use the same flutter engine to launch FlutterActivity, the state remains retained. Sometimes we don&#39;t want this. Thus we have to create a new flutter engine every time and destroy on flutter activity destruction.</p><p>In order to remove all FlutterEngine from the cache, we can use the below command.</p><pre><em>// clear all flutterEngine instance stored in cache<br></em>FlutterEngineCache.getInstance().clear()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9nYKVy4urKIQ_OCr" /></figure><p>The ID passed to the <strong><em>FlutterEngineCache</em></strong> can be whatever one wants. Make sure that ID is the same when you start FlutterActivity.</p><p>Adding some notes from the <a href="https://docs.flutter.dev/development/add-to-app/android/add-flutter-screen?tab=prewarm-engine-kotlin-tab"><strong>official site</strong></a></p><blockquote><strong>Note:</strong> When using a cached FlutterEngine, that FlutterEngine outlives any FlutterActivity or FlutterFragment that displays it. Keep in mind that Dart code begins executing as soon as you pre-warm the FlutterEngine, and continues executing after the destruction of your FlutterActivity/FlutterFragment. To stop executing and clear resources, obtain your FlutterEngine from the FlutterEngineCache and destroy the FlutterEngine with FlutterEngine.destroy().</blockquote><blockquote><strong>Note:</strong> Runtime performance isn’t the only reason that you might pre-warm and cache a FlutterEngine. A pre-warmed FlutterEngine executes Dart code independent from a FlutterActivity, which allows such a FlutterEngine to be used to execute arbitrary Dart code at any moment. Non-UI application logic can be executed in a FlutterEngine, like networking and data caching, and in background behavior within a Service or elsewhere. When using a FlutterEngine to execute behavior in the background, be sure to adhere to all Android restrictions on background execution.</blockquote><p>Thanks! for your precious time. Hope this will help you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd31ba0d130b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add Flutter Module to Android App]]></title>
            <link>https://tanya-anand.medium.com/add-flutter-module-to-android-app-6f35529c752c?source=rss-d1cec1d724a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f35529c752c</guid>
            <category><![CDATA[add-to-app]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[tanya anand]]></dc:creator>
            <pubDate>Tue, 26 Apr 2022 14:10:15 GMT</pubDate>
            <atom:updated>2022-04-28T08:57:13.483Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HBf99DkQ7K_2p8ew" /></figure><p>Welcome to a very very unexplored world…</p><p>I will try to explain what are the ways, we can add flutter to Android App.</p><p>There are mainly two ways to add a flutter module to an android App.</p><ol><li>Add the flutter module as a sibling of the host App.</li><li>Integrate the flutter module as an AAR to host App.</li></ol><p>Let&#39;s learn how to create a flutter module and host app first.</p><p><strong>Creating Android Host App</strong></p><ol><li>Start Android Studio on your system and click on Start a new Android Studio project.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-s6LE8ZNb5qoyaAydbuMNg.png" /></figure><p>2. Choose Empty Activity and click on Next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YalaCfM45EcROf3hJBl06g.png" /></figure><p>3. Enter all required details and click finish.</p><blockquote>Make sure you are keeping host App in a separate folder, this will help us later 😊</blockquote><blockquote>users/flutter-integration/hostApp</blockquote><p>Now, we are all set for the Android host App.</p><p><strong>Creating Flutter module</strong></p><p>The Flutter module should be added as a <em>sibling</em> to the native Android app. Assuming we have an android project at u<em>sers/flutter-integration/hostApp</em>, where <em>hostApp</em> is the name of your Android project folder.</p><p>Now, we have to create the Flutter module in u<em>sers/flutter-integration</em> folder.</p><ol><li>Open the terminal and Navigate to u<em>sers/flutter-integration.</em></li><li>Type below commands</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/349f44b3f8a05187137f95d65bb8ff13/href">https://medium.com/media/349f44b3f8a05187137f95d65bb8ff13/href</a></iframe><p>Now, your flutter module will be generated.</p><p>And new folder structure will be</p><p>flutter-integration -&gt; hostApp + my_flutter</p><p><strong>Wooooh………..👌🏾</strong></p><h3>Method 1</h3><p><strong>Depend on the module’s source code:</strong> This enables a one-step build for both your Android project and Flutter project. This is convenient when working on both parts simultaneously, It also helps a lot in debugging flutter code, hot reload, and hot restart.</p><blockquote>but the team must install the Flutter SDK to build the host app.</blockquote><p>Follow these steps to add Flutter to the native Android app:</p><ol><li>Add below to your host app <em>settings.gradle</em></li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8cde0bfe8bf615b469b13bcc8cca1d6/href">https://medium.com/media/a8cde0bfe8bf615b469b13bcc8cca1d6/href</a></iframe><p>Assuming my_flutter is a sibling to hostApp.</p><p>2. Introduce an implementation dependency on the Flutter module from your app. Add below to your <em>Build.gradle(app)</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62fe4ef5002f6605ac8be99f96c52de4/href">https://medium.com/media/62fe4ef5002f6605ac8be99f96c52de4/href</a></iframe><p>3. Then sync the Gradle by clicking on Sync Now button. This will add some additional code and files to the host app for making it flutter-dependent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gOW4PHDI2tyiGwly" /></figure><p><strong>All Set… We are ready to fly🧚🏼.</strong></p><h3>Method 2</h3><p>This method packages our Flutter library as a generic local Maven repository composed of AARs and POMs artifacts. This allows our team to build the host app without installing the Flutter SDK if you already have AARs. we can then distribute the artifacts from a local or remote repository.</p><p>Follow these steps to add Flutter to the native Android app:</p><ol><li>open the Flutter module at users/flutter-integration/my_flutter, and then run:</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34cf8d2b188460483f0d56a74ace2dc3/href">https://medium.com/media/34cf8d2b188460483f0d56a74ace2dc3/href</a></iframe><p>2. Follow the instructions shown in the terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*lLEw1LiF22uun3eWUCNYrg.png" /></figure><p>edit app/build.gradle in your host app so that it includes the local repository and the dependency:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e9d25762fed9d3ad9b32ad5833a2336/href">https://medium.com/media/8e9d25762fed9d3ad9b32ad5833a2336/href</a></iframe><p><strong>All set !!!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1khvqRsRmpwfLnwb" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f35529c752c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data-Binding takeaways]]></title>
            <link>https://tanya-anand.medium.com/data-binding-takeaways-3f4a7044f49?source=rss-d1cec1d724a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f4a7044f49</guid>
            <category><![CDATA[data-binding]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-data-binding]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[tanya anand]]></dc:creator>
            <pubDate>Tue, 09 Mar 2021 11:14:01 GMT</pubDate>
            <atom:updated>2021-03-09T11:14:01.935Z</atom:updated>
            <content:encoded><![CDATA[<p>Up to this point, in order to update our UI, we have been pushing data into widgets from our Java or Kotlin code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZUYh4vsF2kmHG-uM" /></figure><p>This article explores where to use Android’s data binding support to perhaps simplify your Android app development.</p><p>Data binding is an opt-in feature, in part because it can slow down the build process. For small projects, you will not notice the overhead of the data binding tools, but that overhead becomes more annoying as projects get larger.</p><p>Layout resources with a root &lt;layout&gt; element are processed by the data binding portion of the build system.</p><p>That &lt;layout&gt; element then has two children. The first child is an &lt;data&gt; element, and that is where we configure how data binding should proceed when this layout resource gets used. The second child is our ConstraintLayout, representing the root View or ViewGroup for the resource.</p><p>Inside of &lt;data&gt;, we can use element &lt;import&gt;.This works like import statements in Java or Kotlin, indicating a particular class that we would like to reference. In the world of data binding, mostly we use &lt;import&gt; for classes where we wish to refer to static methods or fields.</p><p>Data binding has its limits. One limit is that it can only access public functions and properties.</p><p>Developers that love data binding seem to focus a lot on the “separation of concerns” that data binding helps to enforce. Your Java/Kotlin code can stop thinking about widget details quite so much, with a lot of that code moving to the layout resources.</p><p>Detractors point out that:</p><ul><li>Data binding slows down the build process, as there is more code generation that needs to go on.</li><li>Data binding can be difficult to debug, as more code is hidden from view, buried in data binding expressions, and generated classes.</li><li>Data binding adds a bit more bloat to a project, adding three libraries and these generated classes, where the user gains very little from the results.</li></ul><p>Google promotes data binding as part of the Jetpack. However, whereas some aspects of Jetpack are nearly unavoidable, data binding is optional. You can use it if you like or skip it if you like.</p><blockquote>Points gathered from Book Elements of Android Jetpack by Mark L. Murphy</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f4a7044f49" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Starting with HILT]]></title>
            <link>https://tanya-anand.medium.com/starting-with-hilt-91d66ff1e1f?source=rss-d1cec1d724a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/91d66ff1e1f</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[dagger-hilt]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[tanya anand]]></dc:creator>
            <pubDate>Sat, 13 Feb 2021 16:26:55 GMT</pubDate>
            <atom:updated>2021-02-13T16:28:55.238Z</atom:updated>
            <content:encoded><![CDATA[<p>HILT made Dependency Injection Easy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a6rrYm_SRbWVa1jV" /></figure><p>Let&#39;s see How...</p><h4><strong>Integrating Dagger-Hilt</strong></h4><p>Add This to your build.gradle(:app)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ff7525c9c5ecaf5d513f7d023a7aa7f/href">https://medium.com/media/2ff7525c9c5ecaf5d513f7d023a7aa7f/href</a></iframe><p>Add this to your build.gradle(project)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2bfbf2892dc5359ea98c39815836aa1b/href">https://medium.com/media/2bfbf2892dc5359ea98c39815836aa1b/href</a></iframe><p>Yup! we are all set.</p><p><em>Don&#39;t forget to click “sync now”</em></p><h4>Step 1</h4><p>Create <em>MyApplication</em> that extends <em>Application</em>.</p><p>We need to annotate with @HiltAndroidApp.</p><p>Hilt needs to know where our application class is, so that it can generate various other dependent classes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/048ef548b1f203cdf062dc1debad0e0e/href">https://medium.com/media/048ef548b1f203cdf062dc1debad0e0e/href</a></iframe><p>Must add this to android manifest as:</p><pre>android:name=&quot;.MyApplication&quot;</pre><h4><strong>Step 2</strong></h4><p>Create class AppModule.kt. which acts as a container for all the dependencies that stay for a specific amount of time.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91513fbee2037140e15fe1c06f47a90a/href">https://medium.com/media/91513fbee2037140e15fe1c06f47a90a/href</a></iframe><p>Let me try to explain it one by one.</p><p><strong>@Module</strong> tells Hilt, this is the place where you can find all dependency providers.</p><p><strong>@InstallIn </strong>tells hilt how longer we need these dependency providers.</p><p><strong><em>SingletonComponent</em></strong><em> </em>tells that, this dependency provider will remain alive till the app is alive. we also have different components as <em>ActivityComponent, ActivityRetainedComponent, etc. which has different life period.</em></p><p><strong>@Singleton</strong> tells hilt, not to create new instance everytime, instead supply the same instance everywhere needed.</p><p><strong>@Named</strong> is used to differentiate between the return type.</p><blockquote>i.e. in the above example, the return type of both function are same. This will confuse Hilt, on which one to bind. To avoid this we give a name to return type.</blockquote><p><strong>Step 3:</strong></p><p>Create ViewModel</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15d68d887a188a26a8b0bb48787c9b41/href">https://medium.com/media/15d68d887a188a26a8b0bb48787c9b41/href</a></iframe><p><strong>@HiltViewModel:</strong> The ViewModel annotated with HiltViewModel will be available for creation and can be retrieved by default in an Activity or Fragment annotated with AndroidEntryPoint.</p><p>it has a dependency <em>RandomStr2 whose return type is String, or distinguished with @Named</em> annotation, This will be injected by Hilt.</p><p><strong>Step 4:</strong></p><p>Now its time for our MainActivity</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/001a1a232cd9cb65bf9f03460786ca96/href">https://medium.com/media/001a1a232cd9cb65bf9f03460786ca96/href</a></iframe><p><strong>@AndroidEntryPoint</strong> tells Hilt, this is file where we have to inject dependencies.</p><pre>@Inject<br>@Named(&quot;Str1&quot;)<br>lateinit var randomString1 : String</pre><p><strong>@Inject</strong> tells Hilt to initialize this variable by dependency injection.</p><p><strong>@Named</strong> is used to differentiate between the return type, which helps dagger to identify dependency provider.</p><pre>private val viewModel : MyViewModel by <em>viewModels</em>()</pre><p>This will create an instance of MyViewModel and store it in ViewModel. This creation is done by lazy instantiation. Thus to call init {} inside MyViewModel.kt we have to call viewModel once.</p><p>We are all set to go!</p><p>Hope this helps you.</p><p><a href="https://github.com/anki-tanya/My-Hilt-App">anki-tanya/My-Hilt-App</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91d66ff1e1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>