<?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 Sangeetha Sakthivel on Medium]]></title>
        <description><![CDATA[Stories by Sangeetha Sakthivel on Medium]]></description>
        <link>https://medium.com/@sakthivelsangeetha99?source=rss-ccd91eef83a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5VBDoN-l6A9K3R61dy8Pww@2x.jpeg</url>
            <title>Stories by Sangeetha Sakthivel on Medium</title>
            <link>https://medium.com/@sakthivelsangeetha99?source=rss-ccd91eef83a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 15:26:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sakthivelsangeetha99/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[SSH for Frontend Devs Who Suddenly Have to Do Deployment]]></title>
            <link>https://medium.com/@sakthivelsangeetha99/ssh-for-frontend-devs-who-suddenly-have-to-do-deployment-3af49b8679ac?source=rss-ccd91eef83a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/3af49b8679ac</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[deployment]]></category>
            <dc:creator><![CDATA[Sangeetha Sakthivel]]></dc:creator>
            <pubDate>Mon, 04 May 2026 16:59:46 GMT</pubDate>
            <atom:updated>2026-05-04T16:59:46.438Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vYk6yETOEUZ4mMpe" /><figcaption>Photo by <a href="https://unsplash.com/@kath_a?utm_source=medium&amp;utm_medium=referral">Katharina Gloth</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I’m a frontend mobile developer. For most of my career, <strong>the server</strong> was just a URL my app talked to(someone else’s problem). Then in April, I started picking up deployment work, and suddenly I had to actually log into servers and do things on them. SSH came up almost immediately, and for the first couple of weeks I was just copy pasting commands from tutorials. Something like:</p><pre>ssh -i mykey.pem ubuntu@54.21.77.200</pre><p>I had no idea what half of that meant. The -i? The .pem? Why ubuntu?</p><p>Then one day when I tried to connect to a server I hit a scary-looking warning:</p><pre>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<br>@    WARNING: REMOTE HOST IDENTIFICATION HAS  @<br>@             CHANGED!                        @<br>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@<br>IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!</pre><p>I panicked. I searched on AI, pasted the commands it gave me, and hoped it worked. It usually did. But I noticed something uncomfortable: I had no idea why the fixes worked.</p><p>That’s when I realized I had no clue what any of this actually did. Time to learn it properly.</p><p>This post is what I picked up, written for someone who’s where I was a week ago.</p><h4>So what’s actually happening when I run that command?</h4><p>Let me go back to that first command:</p><pre>ssh -i mykey.pem ubuntu@54.21.77.200</pre><p>Here’s what each piece is doing:</p><ul><li><strong>ssh — </strong>start a secure connection to a remote computer</li><li><strong>-i mykey.pem</strong> — use this file to prove who I am</li><li><strong>ubuntu</strong> — log in as the user named “<em>ubuntu</em>”</li><li><strong>54.21.77.200</strong> — the server’s IP address</li></ul><p>The interesting part is -i mykey.pem . That file is doing the work of proving I’m allowed into the remote computer / server. But how?</p><h4>The two-key idea</h4><p>When you SSH into a server, the server needs proof that you’re allowed. It used to be passwords, but real setups don’t use those anymore. They use a thing called a <strong>key pair</strong>.</p><p>A key pair is just two files that belong together:</p><pre>id_ed25519       &lt;- private key. lives on YOUR machine(never share)<br>id_ed25519.pub   &lt;- public key. goes on the server</pre><p>The way I finally understood it: think of the public key like a padlock.</p><p><strong>Public key</strong> = the lock<br><strong>Private key</strong> = the key</p><p>You can hand out copies of the padlock to anyone. Put one on your AWS server, one on your GitHub account. The private key is the only thing that opens those padlocks, and it stays on your laptop.</p><p>So when you connect:</p><ol><li>The server has your public key (the padlock)</li><li>Your laptop sends proof that it has the matching private key</li><li>Server says “yep, that checks out” and lets you in</li></ol><p>No password. No typing anything.</p><h4>So what is the .pem file?</h4><p>When you launch an EC2 instance, AWS makes you download a <strong>myKey.pem</strong> file with big warnings about not losing it.</p><p>The .pem file is just a private key.</p><p>That’s it. AWS generated a key pair when you created the instance, put the public key on the server automatically, and gave you the private half as a download.</p><p>So <strong><em>ssh -i myKey.pem</em></strong> literally means use this private key to log in.</p><h4>So why did I get that warning?</h4><p>This is where my brain finally connected the dots. The keys I just described mykey.pem is about me proving who I am to the server.</p><p>But what about the other direction? <strong>How does my laptop know the server is the real server?</strong></p><p>What if someone redirected my traffic to a fake one and I happily typed my commands into it?</p><p>SSH handles this with a second key pair, and this is the one that caused my warning.</p><h4>Every server has its own identity</h4><p>Just like you have a key pair, every SSH server has its own key pair too. Not for users but for the server itself. It’s called a <strong>host key</strong>, and it’s generated automatically when SSH gets installed.</p><p>The first time you connect to a new server, you see this:</p><pre>The authenticity of host &#39;54.21.77.200&#39; can&#39;t be established.<br>ED25519 key fingerprint is SHA256:abc123xyz...<br>Are you sure you want to continue connecting? (yes/no)?</pre><p>When you type yes, your laptop saves the server’s public key to a file:</p><pre>~/.ssh/known_hosts</pre><p>It looks something like:</p><pre>54.21.77.200 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA...<br>github.com ssh-rsa AAAAB3NzaC1yc2EAAAA...</pre><p>Every future connection, your laptop checks: is the key the server is showing me right now the same as what I saved before?</p><ul><li>Same → silent, you’re in</li><li>Different → the warning (someone is doing nasty)</li></ul><p>That’s the whole purpose of known_hosts. Your laptop&#39;s memory of I have seen this server before and here&#39;s what it looked like.</p><h4>When this warning shows up (and why)</h4><p>The warning isn’t always something nasty happening. Common innocent reasons:</p><ul><li><strong>The server got rebuilt or reinstalled.</strong> Fresh OS = freshly generated host keys. Your laptop’s saved key is now stale.</li><li><strong>An EC2 instance was terminated and a new one launched</strong> with the same IP. Same address, totally different machine, different host key.</li><li><strong>Someone ran </strong><strong>ssh-keygen on the server</strong> and regenerated the host keys. (Don&#39;t be that someone 👀)</li></ul><p>In all these cases, the <em>server’s</em> identity has genuinely changed. SSH is doing its job i.e refusing to silently connect to something that looks like a different machine than before.</p><p>The trap is that the warning looks like it’s about your keys (the ones in mykey.pem ). It isn&#39;t. It&#39;s about the server&#39;s keys, sitting in your known_hosts file. That distinction took me embarrassingly long to figure out.</p><h4>How to actually fix it</h4><p>The fix is one command, run on your laptop(local not on remote server 😒):</p><pre>ssh-keygen -R 54.21.77.200</pre><p>That just removes the stale entry from known_hosts. No keys regenerated. No server touched. Your laptop forgets the old key, the next connection prompts you to accept the new one, done.</p><h4>The rule worth memorizing</h4><blockquote><strong><em>ssh-keygen </em></strong><em>always runs on your laptop. Never on the server.</em></blockquote><p>Why? Because it creates a private key. Private keys are supposed to stay on your machine. Run it on the server and one of two bad things happens:</p><ol><li>You regenerate the server’s host keys → break trust for every teammate connecting to it( Prompts someone is doing nasty)</li><li>You create a private key on a machine other people can access → security hole</li></ol><p>This is a thing people do without realizing the damage, especially when they’re new and a tutorial says “just run ssh-keygen&quot; without specifying where ( trust me i didnt do this 🫣)</p><h4>What I haven’t learned yet</h4><p>Stuff I know exists but haven’t gotten to:</p><ul><li>SSH agent (so you don’t unlock your key on every connection)</li><li>SSH tunneling</li><li>Jump hosts</li></ul><p>I’ll get there.</p><h4>The thing I want you to take away</h4><p>SSH is two trust checks happening at once:</p><ul><li>The server checks if you have the right private key</li><li>Your laptop checks if the server’s host key matches what it saw before</li></ul><p>That’s it. Most of the weird errors and warnings you’ll run into are just one of those two checks failing.</p><p>If you’re a frontend or mobile dev who just got handed deployment work, you don’t need to become a sysadmin overnight. You just need to understand what the commands are actually doing.</p><p>If a fix works but you don’t know why, you haven’t really fixed anything. You’ve just delayed the next bug.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3af49b8679ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SOLID Principles — Android]]></title>
            <link>https://medium.com/@sakthivelsangeetha99/solid-principles-android-33339c6c2a4b?source=rss-ccd91eef83a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/33339c6c2a4b</guid>
            <category><![CDATA[solid-principles]]></category>
            <category><![CDATA[design-pattern-kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[agile-development]]></category>
            <dc:creator><![CDATA[Sangeetha Sakthivel]]></dc:creator>
            <pubDate>Thu, 15 Sep 2022 10:36:37 GMT</pubDate>
            <atom:updated>2022-09-15T10:36:37.163Z</atom:updated>
            <content:encoded><![CDATA[<h3>SOLID Principles — Android</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JKfnUuBdfp5anO7A" /><figcaption>Photo by <a href="https://unsplash.com/@gcoppa?utm_source=medium&amp;utm_medium=referral">Guido Coppa</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>What is SOLID Principle?</h3><p>SOLID is an acronym for five design principles in Object-Oriented software development intended to make software designs more understandable, flexible and maintainable.</p><p><strong>SOLID stands for:</strong></p><ul><li><strong>S</strong> — Single-responsiblity Principle</li><li><strong>O</strong> — Open-closed Principle</li><li><strong>L</strong> — Liskov Substitution Principle</li><li><strong>I</strong> — Interface Segregation Principle</li><li><strong>D</strong> — Dependency Inversion Principle</li></ul><h3>Why we need to Follow SOLID Principles?</h3><p>The main goal of the SOLID principles is to <strong>reduce</strong> <strong>dependencies</strong> so that engineers change one area of software without impacting others. Additionally, they’re intended to make designs easier to understand, maintain, and extend. Ultimately, using these design principles makes it easier for software engineers to avoid issues and to build adaptive, effective, and agile software.</p><p><strong>Let’s look at each principle one by one.</strong></p><h4>Single-responsibility Principle:</h4><p>This not only applicable to class but also to functions. A function should have only one responsibility.</p><p><strong>Before Single-responsibility Principle:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O6E6VULCvat2T4mq7fmv3g.png" /></figure><p>In the above example, the onBindViewHolder is violating the Single Responsibility Rule.</p><p>OnBindViewHolder is only responsible to set the data to the view but here it also check whether the employee’s gender. Now the OnBindViewHolder is responsible for more than one thing (Setting data to view and logic around gender). So now i will alter the onBindViewHolder when I want to set the data to new view and also if I want to change the indicator color.</p><p>Ps: Any gender can like any color, the colors used for just an example 😅</p><p><strong>After Single-responsibility Principle:</strong></p><p>Now, let’s look at the correct way to implement the OnBindViewHolder method using SRP principle:</p><p>Seperate the logic from OnBindViewHolder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tStlfXOU_9BkJUnhYNWAJA.png" /></figure><h4>Open-closed Principle:</h4><p>Open/Closed principle states “software entities such as classes, components, modules should be open for extension, but closed for modification”</p><p>This means, if we want to add new feature, instead of adding the feature in the existing code by modifying it , we will extend the class and add the new feature.</p><p><strong>Example:</strong> Consider we are having a home page which greets the user according to the country.</p><p>If Spain “Hola John”. If Japan “konnichiwa John”.</p><p>But Now you want to show “asalaam alaikum John” for Arab.</p><p><strong>Before Open-closed Principle:</strong></p><p>For every new country we need to alter the Greetings class</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dzkJQ8chHttNZNgPnH03mQ.png" /></figure><p><strong>After Open-closed Principle:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tqYiGCPBfv3_V2R2C3vHOA.png" /></figure><h4>Liskov Substitution Principle:</h4><p>The Liskov Substitution Principle states that subclasses should be substitutable for their base classes without changing<strong> </strong>the behavior of base class.</p><p>This means that, given that class B is a subclass of class A, we should be able to pass an object of class B to any method that expects an object of class A and the method should not give any weird output in that case.</p><h4>Interface Segregation Principle</h4><p>A client should never be forced to implement an interface that it doesn’t use, or clients shouldn’t be forced to depend on methods they do not use.</p><p><strong>Before Interface Segregation Principle:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*thyLeZQR2VMVjwiwA0Y6XA.png" /></figure><p>Here every client is forced to implement all the three methods. Even though the client only want to work on onClick.</p><p><strong>After Interface Segregation Principle:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*u1BGEQyOwSMbQfRhwVeCCw.png" /></figure><p>Now client can implement the listener they requires.</p><h4>Dependency Inversion Principle:</h4><p>Dependency inversion principle states that entities must depend on abstractions, not on concretions. this means the high-level module must not depend on the low-level module, but they should depend on abstractions.</p><p>For example, we create a class named virology to study the structure of virus <em>corona</em>. And now we need to do the same for other virus example <em>SARS,</em> then we can’t reuse that same class virology because it is heavily depend on <em>corona</em> virus.</p><p><strong>Before Dependency Inversion Principle:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7MgZFnbV1e9QcPOJthuLSw.png" /></figure><p>By Doing like this we have disadvantages like:</p><ul><li>Unnecessary class files created for same feature.</li><li>No reusability of code</li><li>Testing will be difficult</li><li>Poor readability because naming same feature using different name</li></ul><p><strong>After Dependency Inversion Principle</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b2rvxcu7Sq0R9RqXCPs7SA.png" /></figure><p>Thank you for reading! If you have any feedback please let me know in the comments.</p><figure><a href="https://www.buymeacoffee.com/sangeetha"><img alt="" src="https://cdn-images-1.medium.com/max/260/1*M4ZK9H8apIbI23EWgg_E_g.png" /></a></figure><p>Reference:</p><ul><li><a href="https://www.digitalocean.com/community/conceptual_articles/s-o-l-i-d-the-first-five-principles-of-object-oriented-design">SOLID: The First 5 Principles of Object Oriented Design | DigitalOcean</a></li><li><a href="https://medium.com/kayvan-kaseb/the-solid-principles-for-android-developers-75fd4ca3ef84">The SOLID Principles for Android Developers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33339c6c2a4b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Memory Leak in Android]]></title>
            <link>https://medium.com/@sakthivelsangeetha99/memory-leak-in-android-4f0a6f46f924?source=rss-ccd91eef83a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f0a6f46f924</guid>
            <category><![CDATA[memory-leak]]></category>
            <category><![CDATA[leakcanary]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-memory-management]]></category>
            <dc:creator><![CDATA[Sangeetha Sakthivel]]></dc:creator>
            <pubDate>Mon, 15 Aug 2022 15:12:20 GMT</pubDate>
            <atom:updated>2022-09-15T05:34:48.071Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*uII1QrMAE6T5P47YrV7l7w.jpeg" /></figure><p>Before going to memory leak, let us first understand<em> Garbage Collection</em>. Most of the Android native apps are written on Java or Kotlin. That means that we have a Virtual Machine with a Garbage Collector.</p><h4>So what is Garbage Collection?</h4><p>Garbage collection is the process of looking at heap memory, identifying which objects are in use and which are not, and deleting the unused objects. This memory management process is automatic in Java and Kotlin. The programmer does not need to explicitly mark objects to be deleted.</p><h3>What are memory leaks?</h3><p>When our code allocates memory to an object, but never deallocates it. we call it as memory leak.</p><p>Whenever an object A which is not required is referenced by some other object B which is currently in use, it would make garbage collector to consider object A is still in use.</p><p>Hence garbage collector won’t deallocate object A in memory, this leads to memory leak.</p><h3>Why we need to worry about memory leak?</h3><p>Whenever memory leak happens objects are not deallocated. so heap memory (objects are stored in heap memory) keeps on increasing as the app is being used.</p><p><strong>Case one:</strong> Since memory is needed to create new objects, app will have shortage of memory. As a result of this garbage collector is triggered more frequently to deallocate unused object. Frequent use of Garbage collector leads to poor app performance.</p><p><strong>Case two:</strong> If we have more memory leaks or previous case didn’t solved. we will run into heap memory shortage and get out of memory error and app crashes.</p><h3>Common Causes of memory leak</h3><h4>Improper use of Singletons</h4><p>If a singleton object holds the reference of an activity and lives longer than the activity then there is memory leak.</p><p>Example: Passing activity context to Singleton</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U0J6sqRKxSxsxz6qVCZFOA.png" /></figure><h4>Creating static view reference</h4><p>We know that memory allocation for a static variable happens only once in the class area when the class is loaded in the memory. So when we assign a view reference to a static variable then the view instance wont be garbage collected when it is not in use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*drkjs04DIEv2PS_okdX5Ng.png" /></figure><h4>Improper Use of Handler and Async Task</h4><p>Handler runs task in background thread and it will send a callback onPostDelayed. so the activity is registered to handler. when user back press before the handler finish its job. The activity is no longer in use but since it is registered to the handler, garbage collector thinks that the activity is still in use and it wont deallocate memory.</p><p><strong>Basically, Memory leak happens in the following cases:</strong></p><ul><li>Assigning activity instance to static variable</li><li>Passing activity reference/context to singleton class</li><li>Passing activity reference as a listener to some other class</li><li>Creating static view reference</li><li>Improper use of context</li><li>Unregistered Listeners</li></ul><h3>How to detect memory leak?</h3><p>Memory leak can be detected using <strong><em>Android Profiler</em></strong> and <strong><em>Leak Canary</em></strong> Library.</p><h4>Android Profiler</h4><p>Android Studio provides handy tools for profiling the performance of our app.</p><p>We can use the Memory Monitor to detect memory leaks through the following steps:</p><ul><li>Run your app on your mobile device or an emulator.</li><li>Click <strong>View &gt; Tool Windows &gt; Profiler</strong></li><li>Android Profiler displays the currently profiled process and device.</li><li>Select a session to view in the Sessions window, or start a new profiling session.</li><li>Attach to live button to get straight to the live updates</li><li>The shared timeline view, which shows graphs for CPU, memory, network use.</li></ul><h4>Leak Canary</h4><p>Adding LeakCanary dependency</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E3DpaJbvEQHAoIufmtyTMw.png" /></figure><p>LeakCanary handles memory leaks in four steps as listed below:</p><ul><li>Detecting objects that have been retained.</li><li>Dumping the heap.</li><li>Analyzing the heap.</li><li>Sorting the leaks into categories.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*bwgkR8Th0hFX4YwgVPP2Eg.jpeg" /></figure><p>Thank you for reading! If you have any feedback please let me know in the comments.</p><figure><a href="https://www.buymeacoffee.com/sangeetha"><img alt="" src="https://cdn-images-1.medium.com/max/260/1*M4ZK9H8apIbI23EWgg_E_g.png" /></a></figure><p>Reference: <br><a href="https://www.section.io/engineering-education/handling-memory-leaks-in-android-using-leakcanary/">https://www.section.io/engineering-education/handling-memory-leaks-in-android-using-leakcanary/</a></p><p><a href="https://www.geeksforgeeks.org/memory-leaks-in-android/">https://www.geeksforgeeks.org/memory-leaks-in-android/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f0a6f46f924" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Short Hand RecyclerView Adapter]]></title>
            <link>https://medium.com/@sakthivelsangeetha99/short-hand-recyclerview-adapter-136cea0933e2?source=rss-ccd91eef83a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/136cea0933e2</guid>
            <category><![CDATA[generic-recycler-view]]></category>
            <category><![CDATA[recyclerview-optimization]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[recyclerview-in-android]]></category>
            <dc:creator><![CDATA[Sangeetha Sakthivel]]></dc:creator>
            <pubDate>Thu, 21 Jul 2022 17:10:46 GMT</pubDate>
            <atom:updated>2022-09-15T05:35:57.448Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Goal:</strong> Reduce the boiler plate code of recyclerView adapter</p><p>In this blog, we are going to learn how to reduce the boiler plate code of RecyclerView Adapter in our application by creating a generic adapter class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vr2attaFawvxOSfO" /><figcaption>Photo by <a href="https://unsplash.com/@javaistan?utm_source=medium&amp;utm_medium=referral">Afif Kusuma</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Why we need a Generic Adapter ?</h4><p>We implement RecyclerView in our Android Application when we need to display a list and we do know that for presenting list data in RecyclerView needs RecyclerViewAdapter.</p><p>Usually, us developers create different adapter classes for each recycler view, as a result of that generating boilerplate code. When we have more than one recycler view in our app, we can use a single adapter class which allows all types of data. By doing that we simplify creating RecyclerView adapters and avoid writing boilerplate code.</p><p><strong>Let’s create generic type adapter and view holder.</strong></p><h4>Step 1: Create abstract class</h4><p>This abstract class is going to be our generic adapter. I name this class as <strong><em>WrapperRecyclerAdapter.kt</em></strong><em> </em>you can name this class as you like.</p><p>Usually we pass RecyclerView list data in the constructor, so our generic adapter will also have list data in the constructor. Along with that we will pass our layout id, because RecyclerViewAdapter needs layout to inflate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WsFW0Wk3RsNVf-dKx6XTuQ.png" /></figure><h4>Step 2: Create ViewHolder Class</h4><p>Now we will create our viewHolder class to set the data to the item view. And also we will create an abstract function named setDataToView with paremeter item View and item data this enables binding the data to its respective view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H13UxNep5DpCSuzFYnO4sA.png" /></figure><h4>Step 3: Implement the RecyclerViewAdapter Override Methods</h4><p>As usual we will inflate the view in onCreateViewHolder and bind the data to the view in onBindViewHolder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YpOcbs2JlfmImTB703dDCQ.png" /></figure><p>Thats it our Generic RecyclerViewAdapter is ready to use. Lets see how we can use this Generic Adapter.</p><h4>Step 4: Implement Our Abstract Adapter Class</h4><p>Now we will implement our generic adapter and also implement the setDataToView override method and set the data to view. In my case I just have one Textview so I set the data to the textview.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nqIrtigK7AXiMedRzAcoow.png" /></figure><h4>Step 5: Let’s Set Adapter to our RecyclerView</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z-cq5OE-PHOAHcIC0tJv8g.png" /></figure><p>Want to see the complete code? Here we go</p><p><a href="https://github.com/sangeethasakthivel99/Short-Hand-Adapter">GitHub - sangeethasakthivel99/Short-Hand-Adapter: Goal: Reduce the boiler plate code of recycler view adapter</a></p><p>Thank you for reading! If you have any feedback please let me know in the comments.</p><figure><a href="https://www.buymeacoffee.com/sangeetha"><img alt="" src="https://cdn-images-1.medium.com/max/260/1*M4ZK9H8apIbI23EWgg_E_g.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=136cea0933e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>