<?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 Raj Suvariya on Medium]]></title>
        <description><![CDATA[Stories by Raj Suvariya on Medium]]></description>
        <link>https://medium.com/@rajsuvariya?source=rss-4b86b902db4b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Lb2G9DES-Y7wizbr.</url>
            <title>Stories by Raj Suvariya on Medium</title>
            <link>https://medium.com/@rajsuvariya?source=rss-4b86b902db4b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 05:41:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rajsuvariya/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[TiDB vs Traditional MySQL Clusters: When to Migrate and Why?]]></title>
            <link>https://medium.com/@rajsuvariya/tidb-vs-traditional-mysql-clusters-when-to-migrate-and-why-0b7d18dad2fd?source=rss-4b86b902db4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/0b7d18dad2fd</guid>
            <category><![CDATA[tidb]]></category>
            <category><![CDATA[sharding]]></category>
            <category><![CDATA[horizontal-scaling]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Raj Suvariya]]></dc:creator>
            <pubDate>Sun, 09 Mar 2025 05:41:37 GMT</pubDate>
            <atom:updated>2025-03-09T05:41:37.844Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>🚀 <strong>Is your MySQL cluster holding you back?</strong> Maybe it’s time to take the leap.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BwBtt4h-rtAFM7DL.png" /></figure><p>We are witnessing a technological revolution unfold, one where data has become the new currency. The ability to collect, process, and analyze massive amounts of data now defines a company’s competitive edge. As businesses grow, so do their data storage and processing needs, making database scalability a critical factor in long-term success.</p><p>For years, MySQL has been a trusted choice for managing structured data. However, as data volumes explode and performance demands increase, traditional MySQL clusters often struggle with scalability, operational complexity, and consistency challenges. This is where TiDB, a distributed SQL database, emerges as a powerful alternative — offering seamless horizontal scaling, automatic sharding, and strong consistency.</p><p>But when should you consider migrating from a traditional MySQL cluster to TiDB? In this blog, we’ll explore the key differences, performance trade-offs, and real-world scenarios where making the switch can drive greater efficiency, reliability, and growth.</p><h3>Problems with Traditional MySQL for High Data Growth and High Traffic</h3><p>As data grows, so does the need for storage and computational power. Scaling a MySQL database to accommodate increasing business demands can quickly become challenging. Here are some common approaches to handling this growth — and the limitations they bring.</p><h4>1. The Limits of Vertical Scaling</h4><p>At first glance, vertical scaling (increasing disk size or upgrading to a more powerful instance) seems like an easy solution. However, this approach has significant drawbacks:</p><ul><li><strong>Infrastructure Constraints:</strong> If the disk doesn’t support elastic scaling, upgrading requires a major migration effort.</li><li><strong>Scaling Limits:</strong> Even with elastic scaling, there is an upper limit beyond which vertical scaling is no longer feasible.</li><li><strong>Compute Bottleneck:</strong> Increasing disk size alone doesn’t solve compute limitations. As traffic grows alongside data, a single database instance will struggle to handle all the read and write operations, leading to performance degradation.</li></ul><h4>2. The Challenges of Sharding</h4><p>Sharding, or distributing data across multiple MySQL instances, is a common way to scale beyond vertical limitations. However, it introduces several complexities:</p><ul><li><strong>Application-Level Complexity:</strong> Existing data must be split across multiple clusters, and the application logic must be updated to query the correct shard.</li><li><strong>Joins across shards: </strong>Joins across shards become difficult, often requiring <strong>denormalization</strong> or the use of a separate query-routing layer.</li><li><strong>Consistency Issues:</strong> Maintaining strong consistency for transactions spanning multiple shards becomes challenging, especially as the system scales.</li><li><strong>Maintenance Overhead:</strong> More shards mean increased operational complexity, requiring additional monitoring and management.</li><li><strong>Hot Shards:</strong> If the data distribution strategy is not carefully planned, some shards may receive disproportionate traffic, leading to performance bottlenecks.</li></ul><h4>3. Risk of Data Loss and Availability</h4><p>MySQL clusters commonly use a <strong>Master-Slave (Primary-Replica) architecture</strong> for high availability. However, this setup comes with an inherent risk:</p><ul><li><strong>Asynchronous Replication:</strong> Most MySQL deployments rely on async replication, which means there is always a risk of data loss in high-traffic systems.</li><li><strong>Failover Gaps:</strong> In the event of a master node failure, some recent writes may not have been replicated to the slave, leading to potential data inconsistency.</li><li><strong>Availability Gaps: </strong>In the event of a master node failure, systems need to detect the failure and initiate a failover which often takes time from a few seconds to minutes, during this time your application cannot read or write from these shards.</li></ul><h4>4. The Challenge of Scaling Strongly Consistent Reads</h4><p>MySQL relies on <strong>replicas</strong> to scale read-heavy workloads by distributing queries across read replicas. However, this approach has fundamental limitations:</p><ul><li><strong>Replication Lag:</strong> MySQL’s asynchronous replication means <strong>read replicas lag behind the primary database</strong>, leading to stale data being served. This is especially problematic for applications requiring <strong>real-time consistency</strong>.</li><li><strong>Eventual Consistency Issues:</strong> Applications that need <strong>strongly consistent reads (e.g., financial systems, real-time analytics)</strong> must query the master instance, which can quickly become a bottleneck.</li><li><strong>Operational Overhead:</strong> Ensuring low replication lag requires <strong>tuning, monitoring, and potentially sacrificing write performance</strong>.</li></ul><h4>5. The Complexity of Implementing HTAP (Hybrid Transactional and Analytical Processing)</h4><p>Modern applications often require <strong>both transactional (OLTP) and analytical (OLAP) workloads</strong> on the same data. MySQL, however, was designed primarily for <strong>OLTP</strong> and struggles with real-time analytics.</p><ul><li><strong>ETL Delays:</strong> MySQL typically requires <strong>extracting data (ETL) into a separate OLAP database</strong> (e.g., ClickHouse, Redshift), creating processing delays.</li><li><strong>Performance Bottlenecks:</strong> Running complex analytical queries (e.g., JOINs, GROUP BY, COUNT(*)) on MySQL slows down the primary transactional workload.</li><li><strong>Separate Data Pipelines:</strong> Maintaining <strong>two separate databases (OLTP + OLAP)</strong> increases infrastructure and operational complexity.</li><li><strong>Limited Indexing Optimization:</strong> MySQL indexes are optimized for point lookups but <strong>struggle with high-speed analytical queries on large datasets</strong>.</li></ul><h3>When to migrate to TiDB (Distributed SQL Database)?</h3><h4>1. When You Need Horizontal Scalability Without Sharding Pain</h4><ul><li>MySQL requires <strong>manual sharding</strong>, but TiDB <strong>automatically distributes</strong> data across multiple nodes.</li><li>No need to <strong>rewrite application logic</strong> for query routing or handling cross-shard transactions.</li><li>Ideal for growing applications that <strong>frequently outgrow single-node MySQL setups</strong>.</li></ul><p><strong>✅ Migrate If:</strong></p><p>✔ Your dataset is growing <strong>beyond a single MySQL instance’s capacity</strong>.<br>✔ You’ve already <strong>sharded MySQL manually and are struggling with maintenance</strong>.<br>✔ You want a database that can <strong>scale out seamlessly</strong> by simply adding nodes.</p><h4>2. When You Need Strong Consistency and Distributed Transactions</h4><ul><li>In sharded MySQL, transactions across shards require <strong>complex workarounds (2PC, eventual consistency models)</strong>.</li><li>TiDB provides <strong>ACID transactions natively across multiple nodes</strong>, similar to traditional MySQL but in a <strong>distributed fashion</strong>.</li></ul><p><strong>✅ Migrate If:</strong></p><p>✔ You need <strong>global consistency</strong> but don’t want to deal with <strong>compensating transactions</strong> or distributed locks.<br>✔ Your application requires <strong>cross-shard transactions</strong> (e.g., financial systems, order processing).</p><h4>3. When High Write Throughput Overwhelms MySQL</h4><ul><li>Traditional MySQL struggles with write-heavy workloads due to <strong>single-node bottlenecks</strong>.</li><li>TiDB uses <strong>distributed storage (TiKV) and Raft-based consensus</strong>, enabling <strong>high write throughput without locking contention</strong>.</li></ul><p><strong>✅ Migrate If:</strong></p><p>✔ Your MySQL instance is hitting <strong>write bottlenecks</strong> despite indexing and query optimizations.<br>✔ Your application has <strong>high insert/update frequency</strong> (e.g., real-time analytics, financial transactions).</p><h4>4. When you need strong consistent reads</h4><ul><li>MySQL scales reads using <strong>replicas</strong>, but managing replication lag and strong consistency can be complex.</li><li>TiDB <strong>automatically balances reads across distributed nodes</strong>, ensuring <strong>consistent reads at scale</strong>.</li></ul><p><strong>✅ Migrate If:</strong></p><p>✔ Your MySQL read replicas are <strong>struggling with replication lag</strong>.<br>✔ You have <strong>strong consistency read requirements</strong> (e.g., financial data).</p><h4>5. When You Need HTAP (Hybrid Transactional and Analytical Processing)</h4><ul><li>Running <strong>real-time analytics on MySQL</strong> usually requires <strong>ETL pipelines</strong> to export data into OLAP engines (e.g., ClickHouse, Redshift).</li><li>TiDB’s <strong>TiFlash engine</strong> allows you to <strong>run real-time analytical queries directly on operational data</strong>.</li></ul><p><strong>✅ Migrate If:</strong></p><p>✔ You need to <strong>analyze transactional data in real-time</strong> without ETL delays.<br>✔ You’re maintaining <strong>separate OLTP and OLAP systems</strong> but want a <strong>unified solution</strong>.</p><h4>6. When Managing MySQL Infrastructure Becomes Too Complex</h4><ul><li>Scaling MySQL involves <strong>manual resharding, replica management, failover handling, and backup complexity</strong>.</li><li>TiDB <strong>automates cluster management</strong>, making operations <strong>simpler and cost-effective</strong>.</li></ul><p><strong>✅ Migrate If:</strong></p><p>✔ Your team is <strong>spending too much time on MySQL infrastructure maintenance</strong>.<br>✔ You want a <strong>Kubernetes-friendly, cloud-native database</strong> for easier deployment and scaling.</p><h3>Conclusion: Future-Proofing Your Data Architecture</h3><p>While MySQL has been a reliable choice for decades, its limitations in <strong>scalability, consistency, and operational complexity</strong> become apparent at high data volumes and traffic. The workarounds — sharding, replication, and external analytics pipelines — only introduce <strong>more overhead, maintenance burden, and architectural complexity</strong>.</p><p>TiDB offers a modern alternative, <strong>combining the familiarity of MySQL with the power of distributed SQL</strong>. With <strong>automatic sharding, strong consistency, seamless horizontal scaling, and built-in HTAP capabilities</strong>, it eliminates many of the pain points associated with scaling traditional MySQL clusters.</p><p>If you find yourself constantly <strong>rescaling infrastructure, battling replication lag, struggling with distributed transactions, or maintaining separate OLTP and OLAP systems</strong>, it might be time to <strong>consider migrating to TiDB</strong>. By embracing a <strong>cloud-native, distributed SQL solution</strong>, you can future-proof your database strategy and focus on <strong>building applications that scale effortlessly</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0b7d18dad2fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating TiDB Planned Maintenance with k8s Operator]]></title>
            <link>https://blog.flipkart.tech/automating-tidb-planned-maintenance-with-k8s-operator-5893f3ffb657?source=rss-4b86b902db4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5893f3ffb657</guid>
            <category><![CDATA[maintenance]]></category>
            <category><![CDATA[tidb]]></category>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[k8s-operator]]></category>
            <dc:creator><![CDATA[Raj Suvariya]]></dc:creator>
            <pubDate>Sun, 29 Sep 2024 16:18:11 GMT</pubDate>
            <atom:updated>2024-09-30T06:15:58.440Z</atom:updated>
            <content:encoded><![CDATA[<p>TiDB is an open-source relational distributed SQL-compatible database. It is compatible with MySQL clients and stores data in key-value stores underneath. As it is distributed in nature, it provides additional features such as horizontal scalability and high availability over the traditional MySQL.</p><p>We are a platform team at Flipkart hosting TiDB on k8s for business use cases cross-cutting multiple systems across the length and breadth of Flipkart; primarily serving OLTP workloads, with a few using OLAP workloads.</p><h3>A bit of TiDB Database</h3><h4>TiDB Architecture</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7cZr5Qxt50-5CtyCY8edVw.png" /><figcaption><a href="https://docs.pingcap.com/tidb/stable/tidb-architecture">https://docs.pingcap.com/tidb/stable/tidb-architecture</a></figcaption></figure><h4>TiDB Terminology</h4><p><strong>Region</strong>: A smaller data chunk, generally 96MB.</p><p><strong>PD (Placement Driver)</strong>: Component that is the brain of the entire TiDB Database architecture. It manages region scheduling, key distribution, and issues transaction IDs.</p><p><strong>TiKV: </strong>Key value store which holds all the data in a key-value form and uses RocksDB underneath.</p><p><strong>TiDB: </strong>MySQL interface over TiKV, which processes SQL queries, aggregates results from multiple TiKVs, and handles DDL queries.</p><p><strong>TiFlash:</strong> Key-value store similar to TiKV used for OLAP queries.</p><p><strong>TiCDC:</strong> A component used for change data capture use cases and various supported downstream databases such as MySQL, Kafka, Pulsar, and TiDB.</p><p><strong>Monitor:</strong> The component that monitors the entire TiDB cluster, and it hosts Prometheus and Grafana services.</p><h4>High Availability and Durability of TiDB</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U5J0oOQLrfKANPONPS3VEg.png" /></figure><p>TiDB stores multiple replicas (by default 3) on different TiKV nodes, as illustrated, to ensure the High Availability of the database and durability of the data stored on the database. These replicas form a quorum based on Raft (majority consensus), so the database can continue to operate even when 2 out of 3 replicas are available. Therefore, one pod failure will not affect the overall database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q3bZ3nc5579efUH__ZD9_Q.png" /><figcaption>Region 2, 3, and 4 have only 2 replicas after the TiKV node 3 dies</figcaption></figure><p>In case of a failure, the TiDB operator detects the failure and begins the recovery, wherein an additional pod is spawned and data can be copied to the new node from the latest replicas of all the regions hosted on the failed pod.</p><p>During this time, when data copy is in progress, one more pod failure can take down the entire cluster. We refer to this as an unplanned failure tolerance.</p><p>For more details about how high availability is ensured in TiDB, please refer to the official <a href="https://docs.pingcap.com/tidb-in-kubernetes/stable/tidb-operator-overview">TiDB documentation</a>.</p><h3>Infra at Flipkart</h3><p>The backbone of Flipkart’s technological landscape lies in its robust in-house infrastructure which spans across two in-house data centers. This helps Flipkart ensure accurate control, security, and reliability.</p><p>Flipkart uses different hardware and persistence layers, catering optimally to different use cases. For example, latency-sensitive workloads use local SSD disks and highest generation vcores, whereas latency-insensitive workloads use NAS (Network-Attached Storage) and lower generation vcores. This helps balance the performance vs. cost tradeoff.</p><h3>Problem Statement</h3><p>For critical databases, we use local SSD disks, but it comes with certain drawbacks. If there is any issue with the Compute of the node, it cannot be recreated on any other Compute server considering the data is locally attached and cannot be accessed from outside. In case of any detected issue that requires hardware to be taken out for maintenance, the k8s team cannot reschedule the pods without the involvement of the database team. So the k8s team schedules maintenance and informs the database teams to move out of such nodes.</p><p>The database team cannot ignore rescheduling such affected nodes because, as mentioned earlier, TiDB can only tolerate one node failure. If we ignore such scheduled maintenance, it can cause an unplanned failure (even though it was planned) and one actual unplanned failure can take down the entire database.</p><p>When we have information about scheduled maintenance, we have to move out of such nodes by creating additional replicas to ensure that each region has 3 replicas during the data copy (referred to as rebalancing).</p><p>It is a common concern that the TiDB operator does not handle such a workflow. Most of the public clouds run on NAS where the Compute can be easily rescheduled on different servers without rebalancing of data, unlike the specific use case in Flipkart, where we use local PVs (Persistent Volumes) to enhance disk performance.</p><p>In this context, our Kubernetes (k8s) operator plays a vital role by automating the movement of specified TiDB components, ensuring seamless operations, and minimising downtime. This operator addresses the complexities specific to our infrastructure, enhancing both efficiency and reliability.</p><h3>Why Automation?</h3><p>Automation ensures that each step is executed precisely, significantly reducing the potential for mistakes and freeing up valuable on-call capacity. Our k8s operator meticulously handles each required step, ensuring a seamless transition without the risk of human error. By automating these maintenance tasks, we not only enhance operational efficiency but also improve the reliability of our infrastructure.</p><p>In this blog, we delve into the architecture and functionality of our k8s operator, demonstrating how it supports our maintenance processes and improves our operational resilience.</p><h3>Why k8s operator?</h3><p>We evaluated multiple approaches, including scripting, using our backend service, k8s jobs, etc., before we chose the k8s operator based on the following evaluations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jfIzwIOoxpuXsMbst_CEBg.jpeg" /></figure><p><strong>Native Kubernetes Integration: </strong>As<strong> </strong>all actions are performed within the Kubernetes cluster, leveraging a k8s operator aligns seamlessly with our existing infrastructure and operational workflows.</p><p><strong>Control Loop Capabilities: </strong>Kubernetes control loops enable the execution of small, synchronized tasks and support re-queuing reconciliation when asynchronous tasks, such as region migrations in TiKV, are pending verification.</p><p><strong>Fault-Tolerant Design: </strong>The operator architecture ensures fault tolerance. If the operator pod responsible for maintenance fails, the next pod seamlessly takes over and resumes operations from the last checkpoint, ensuring continuity and reliability.</p><p><strong>High Availability (HA) Support: </strong>The solution can be made highly available by deploying multiple operator pods and implementing leader election mechanisms, reducing single points of failure and enhancing operational robustness.</p><p><strong>Extensibility to Other DBaaS Products: </strong>Beyond TiDB, the operator’s architecture can be extended to support other Database as a Service (DBaaS) products at Flipkart, offering a unified approach to managing diverse DBaaS services within our ecosystem.</p><p>We used an <a href="https://sdk.operatorframework.io/">operator-sdk</a> framework to streamline development, allowing us to focus on defining reconciliation logic. This framework abstracts Kubernetes API complexities, accelerates development with built-in tools, and ensures robust integration with Kubernetes, enabling efficient management of our TiDB components.</p><h4><strong>CRD</strong></h4><p>Our custom resource definition (CRD) focuses on simplicity, specifying only a scheduled start time for maintenance and the PVC name associated with the pod scheduled for deletion, sample CR as below.</p><pre>apiVersion: maintenance.tidb.flipkart.com/v1alpha1<br>kind: TiDBScheduledMaintenance<br>metadata:<br>  name: maintenance-tikv-test-maintenance-hyd-tikv-0<br>  namespace: test-namespace<br>spec:<br>  pvcName: tikv-test-maintenance-hyd-tikv-0<br>  startTime: &quot;2024-06-26T16:30:00+05:30&quot;</pre><p>We use the PVC name in the CRD instead of the pod’s name to focus on managing local persistent volume (PV) disks. Kubernetes permits pods to mount multiple disks, including a mix of local and network-attached volumes. Therefore, leveraging PVC names ensures accuracy in targeting disk-specific maintenance activities, enhancing scalability, and operational clarity within our infrastructure.</p><h4>Identifying TiDB Cluster and Component from PVC Name</h4><p>Identifying the TiDB cluster and its components from just the PVC name could have been challenging, involving iteration over pods or string manipulation. Fortunately, the TiDB operator labels PVCs with this information, simplifying identification by making all necessary details readily available.</p><pre>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  ...<br>  labels:<br>    app.kubernetes.io/component: tikv<br>    app.kubernetes.io/instance: tidb-cluster-1<br>    app.kubernetes.io/managed-by: tidb-operator<br>    app.kubernetes.io/name: tidb-cluster<br>    tidb.pingcap.com/cluster-id: &quot;7385505036965769661&quot;<br>    tidb.pingcap.com/pod-name: tidb-cluster-1-tikv-0<br>    tidb.pingcap.com/store-id: &quot;1&quot;<br>  name: tikv-tidb-cluster-1-tikv-0<br>  namespace: test-namespace<br>spec:<br>  ...</pre><h4>Connection with PD</h4><p>As it is clear from the manual steps, our operations frequently rely on data from PD — such as stores, member statuses, and triggers for store or member deletions — making it essential for the operator to establish a connection with PD.</p><p>To adhere to the DRY (Don’t Repeat Yourself) principle, we seamlessly integrated the <a href="https://github.com/pingcap/tidb-operator/blob/master/pkg/pdapi/pdapi.go">pdapi</a> interface from the <a href="https://github.com/pingcap/tidb-operator/tree/master">tidb-operator</a>. This interface already supports all necessary calls to the PD REST API client, ensuring efficiency and consistency in our operations.</p><h4>Reconciliation</h4><p>Once we identified TiDBCluster and Component with scheduled start time and a PD connection, all we had to do was to write a simple reconciliation that automates the steps described below.</p><h4>Steps to migrate data out of each TiDB component</h4><p>We followed a few steps to move out the TiDB components that use the local PV storage.</p><blockquote><strong><em>PD (Placement Driver)</em></strong></blockquote><p><em>Check Leadership:</em></p><ul><li>Determine if the affected pod is currently acting as the leader. If it is, initiate the process for the leader’s resignation using the following command:</li></ul><pre>./pd-ctl member leader resign</pre><p><strong><em>Scale-out PD replicas</em></strong></p><ul><li>To ensure one more unplanned failure doesn’t take down the cluster we scale out the PD cluster by 2 replicas, which can continue to operate with 3 replicas alive, hence allowing one planned and one unplanned failure at the same time without any disruption.</li></ul><p><strong><em>Delete Member</em></strong><em>:</em></p><ul><li>To remove the member from the PD cluster, execute the following command:</li></ul><pre>./pd-ctl member delete name &lt;POD_NAME&gt;</pre><p><strong><em>Delete Pod and PVC</em></strong><em>:</em></p><ul><li>Delete the pod and its associated Persistent Volume Claim (PVC) for the affected pod.</li></ul><pre>kubectl delete pvc/&lt;PVC_NAME&gt; pod/&lt;POD_NAME&gt; --context &lt;k8s_context&gt; -n &lt;k8s_namespace&gt;</pre><p><strong><em>Verify New Pod Creation</em></strong><em>:</em></p><ul><li>Ensure that a new pod with the same ordinal is created and successfully registered with the PD cluster. Verify this using the following command:</li></ul><pre>./pd-ctl member</pre><p><strong><em>Scale-in PD replicas</em></strong></p><ul><li>Scale-in 2 PD replicas which were added during maintenance.</li></ul><blockquote><strong><em>TiKV / TiFlash</em></strong></blockquote><p><strong><em>Scale-Out TiKV:</em></strong></p><ul><li>Increase the number of TiKV / TiFlash replicas to ensure that the number of alive replicas matches the configured replicas initially.</li></ul><p><strong><em>Validate Scale-Out:</em></strong></p><ul><li>Verify the successful scaling out by ensuring that the new TiKV / TiFlash pod has been provisioned and a new store has been created for it with PD.</li></ul><pre>./pd-ctl store</pre><p><strong><em>Delete Store:</em></strong></p><ul><li>Delete the store associated with the affected TiKV / TiFlash. This step removes the TiKV / TiFlash instance from the cluster.</li></ul><pre>./pd-ctl store delete &lt;STORE_ID&gt;</pre><p><strong><em>Wait for Rebalancing:</em></strong></p><ul><li>Monitor the status of the rebalancing process to ensure that all regions have been moved out from the affected TiKV / TiFlash nodes. Check the status continuously using the following command:</li></ul><pre>./pd-ctl store &lt;STORE_ID&gt;</pre><p><strong><em>Delete Pod and PVC:</em></strong></p><ul><li>Once rebalancing is completed, all data has been migrated, and store status has moved to tombstone, delete the TiKV / TiFlash pod and its associated Persistent Volume Claim (PVC) for recreating them.</li></ul><pre>kubectl delete pvc/&lt;PVC_NAME&gt; pod/&lt;POD_NAME&gt; --context &lt;k8s_context&gt; -n &lt;k8s_namespace&gt;</pre><p><strong><em>Validate Store Registration:</em></strong></p><ul><li>Ensure that the store for the recreated TiKV / TiFlash pod has been successfully registered with PD. Verify this using:</li></ul><pre>./pd-ctl store</pre><p><strong><em>Initiate Scale-In:</em></strong></p><ul><li>After confirming the successful migration and store registration, initiate a scale-in operation for the TiDB cluster to remove any additional replicas that were added during the migration.</li></ul><blockquote><strong><em>TiCDC</em></strong></blockquote><p><strong><em>Delete Pod and PVC:</em></strong></p><ul><li>Delete the TiCDC pod and its associated Persistent Volume Claim (PVC) to prepare for recreating the affected pod. Unlike other components, there is no need to pause the change feeds because the metadata about change feeds resides in PD, not on the TiCDC pod’s disk.</li></ul><h3>Almost Done!</h3><p>We’ve reached a point where our operator is functionally ready to perform maintenance on the TiDB cluster. However, we must also address non-functional requirements (NFRs) to ensure minimal performance impact on the cluster.</p><p>When multiple maintenance operations on TiKV or TiFlash run in parallel, data migration can consume significant CPU resources, potentially causing resource over-utilisation and affecting running queries. Therefore, it’s crucial to run these maintenance tasks sequentially to avoid compounding the CPU impact.</p><p>We implemented a locking mechanism using TiDBCluster CR annotations to manage sequential execution. When a maintenance operation locks the resource, it runs first, while others wait and periodically check for the lock every 5 minutes. Once the running maintenance completes and releases its lock, the next maintenance can acquire the lock and proceed.</p><pre>apiVersion: pingcap.com/v1alpha1<br>kind: TidbCluster<br>metadata:<br>  annotations:<br>    maintenance.flipkart.com/maintenance-status: InProgress<br>    maintenance.flipkart.com/active-maintenance: maintenance-tikv-test-maintenance-hyd-tikv-0<br>    ...</pre><p>Kubernetes resource updates ensure pessimistic locking. In this mechanism, if two threads attempt to read and update the same resource concurrently, the Kubernetes API server handles the conflict. When one thread updates the resource, it increments the resource version. The next thread, upon attempting an update, will detect that the resource version has changed and will be marked as a conflict. This ensures that only one maintenance operation acquires the lock in case of race conditions, thereby preventing the simultaneous execution of conflicting tasks.</p><pre>func (r *TidbReconciler) lockTidbClusterForMaintenance(<br>   ctx context.Context, tc *pingcapv1alpha1.TidbCluster, maintenanceName string,<br>) error {<br>   tcCopy := tc.DeepCopy()<br>   if tcCopy.Annotations == nil {<br>      tcCopy.Annotations = make(map[string]string)<br>   }<br>   tcCopy.Annotations[utils.AnnotationMaintenanceStatus] = v1alpha1.StatusInProgress<br>   tcCopy.Annotations[utils.AnnotationActiveMaintenance] = maintenanceName<br>   err := r.Client.Update(ctx, tcCopy)<br>   return err<br>}</pre><pre>// Try to lock TiDB cluster<br>err := appReconciler.lockTidbClusterForMaintenance(ctx, tc, maintenanceName)<br>if err != nil {<br>   if apierrors.IsConflict(err) {<br>      logger.Error(<br>         err, fmt.Sprintf(<br>         &quot;Failed to lock maintenance for %s due to conflict, requeue the request&quot;, utils.AppTiDBCluster,<br>         ),<br>      )<br>      // lock failed due to conflict, retry the lock<br>      return ctrl.Result{RequeueAfter: time.Minute * 5}, nil<br>   }<br>   // lock failed due to other error, mark the CR failed<br>   logger.Error(<br>      err, fmt.Sprintf(&quot;Failed to lock maintenance for %s&quot;, utils.AppTiDBCluster),<br>   )<br>   r.StatusUpdater.MarkCRStatusFailed(ctx, scheduledMaintenance, logger)<br>   return ctrl.Result{}, err<br>}<br><br>// lock succeeded, mark current CR InProgress<br>statusErr := r.StatusUpdater.MarkCRInProgress(ctx, scheduledMaintenance, logger)</pre><p>Given the low frequency of multiple maintenance on the same cluster, this implementation approach balances simplicity with efficiency.</p><h3>And we are done!</h3><p>And that’s how we implemented our Kubernetes operator to handle scheduled movements ahead of maintenance at Flipkart. As we continue to refine and expand its capabilities, we look forward to further optimising our infrastructure management and enhancing operational resilience at Flipkart.</p><h3>Results</h3><p>Ever since it has been deployed in production, the maintenance operator has yielded impressive results. The operator has successfully handled hundreds of maintenance tasks, significantly reducing our on-call workload and ensuring consistency throughout each process step. By leveraging this operator, we have not just saved a lot of operational hours, but also brought significant reliability to the system by removing the human error from the process.</p><p>That’s our journey in developing the Kubernetes operator for managing scheduled movements ahead of maintenance at Flipkart. As we continue to innovate and refine our infrastructure management practices, we remain committed to leveraging technology for delivering exceptional performance and service reliability. We look forward to sharing more insights and advancements in the future.</p><p><strong><em>References</em></strong><br><a href="https://docs.pingcap.com/tidb/stable/pd-control"><em>https://docs.pingcap.com/tidb/stable/pd-control</em></a><em><br></em><a href="https://docs.pingcap.com/tidb-in-kubernetes/stable/maintain-a-kubernetes-node#if-the-node-storage-cannot-be-automatically-migrated"><em>https://docs.pingcap.com/tidb-in-kubernetes/stable/maintain-a-kubernetes-node#if-the-node-storage-cannot-be-automatically-migrated</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5893f3ffb657" width="1" height="1" alt=""><hr><p><a href="https://blog.flipkart.tech/automating-tidb-planned-maintenance-with-k8s-operator-5893f3ffb657">Automating TiDB Planned Maintenance with k8s Operator</a> was originally published in <a href="https://blog.flipkart.tech/">Flipkart Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SOLID Principles — explained with examples]]></title>
            <link>https://medium.com/mindorks/solid-principles-explained-with-examples-79d1ce114ace?source=rss-4b86b902db4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/79d1ce114ace</guid>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Raj Suvariya]]></dc:creator>
            <pubDate>Wed, 11 Apr 2018 06:10:13 GMT</pubDate>
            <atom:updated>2022-11-25T03:23:06.407Z</atom:updated>
            <content:encoded><![CDATA[<p>Writing a code which satisfies present requirements, also which can satisfy future requirement easily, should be the goal of every developer. Evolving with the time is the only factor which can keep you going, otherwise, you all know what happened with Nokia and Canon brand. SOLID principles help you to write such code.</p><p>What does the <strong>SOLID</strong> principles actually means? Well, it’s just an acronym of the five principles listed as below.</p><ul><li><strong>S</strong> - Single Responsibility Principle (known as SRP)</li><li><strong>O</strong> - Open/Closed Principle</li><li><strong>L</strong> - Liskov’s Substitution Principle</li><li><strong>I</strong> - Interface Segregation Principle</li><li><strong>D</strong> - Dependency Inversion Principle</li></ul><p>Let’s try to understand what all these principles means, one by one with examples.</p><blockquote><strong>S — Single Responsibility Principle (known as SRP)</strong></blockquote><p>The name itself suggest that the “class should be having one and only one responsibility”. What does it mean? Well let’s take the class A which does the following operations.</p><ul><li>Open a database connection</li><li>Fetch data from database</li><li>Write the data in an external file</li></ul><p>The issue with this class is that it handles lot of operations. Suppose any of the following change happens in future.</p><ul><li>New database</li><li>Adopt ORM to manage queries on database</li><li>Change in the output structure</li></ul><p>So in all the cases the above class would be changed. Which might affect the implementation of the other two operations as well. So ideally according to SRP there should be three classes each having the single responsibility.</p><blockquote><strong>O — Open/Closed Principle</strong></blockquote><p>This principle suggests that “classes should be open for extension but closed for modification”. What is means is that if the class A is written by the developer AA, and if the developer BB wants some modification on that then developer BB should be easily do that by extending class A, but not by modifying class A.</p><p>The easy example would be the RecyclerView.Adapter class. Developers can easily extend this class and create their own custom adapter with custom behaviour without modifying the existing RecyclerView.Adapter class.</p><blockquote><strong>L — Liskov’s Substitution Principle</strong></blockquote><p>This principle suggests that “parent classes should be easily substituted with their child classes without blowing up the application”. Let’s take following example to understand this.</p><p>Let’s consider an Animal parent class.</p><pre><strong>public class </strong>Animal {<br>    <strong>public void </strong>makeNoise() {<br>        System.<strong><em>out</em></strong>.println(<strong>&quot;I am making noise&quot;</strong>);<br>    }<br>}</pre><p>Now let’s consider the Cat and Dog classes which extends Animal.</p><pre><strong>public class </strong>Dog <strong>extends </strong>Animal {<br>    @Override<br>    <strong>public void </strong>makeNoise() {<br>        System.<strong><em>out</em></strong>.println(<strong>&quot;bow wow&quot;</strong>);<br>    }<br>}<br><br><strong>public class </strong>Cat <strong>extends </strong>Animal {<br>    @Override<br>    <strong>public void </strong>makeNoise() {<br>        System.<strong><em>out</em></strong>.println(<strong>&quot;meow meow&quot;</strong>);<br>    }<br>}</pre><p>Now, wherever in our code we were using Animal class object we must be able to replace it with the Dog or Cat without exploding our code. What do we mean here is the child class should not implement code such that if it is replaced by the parent class then the application will stop running. For ex. if the following class is replace by Animal then our app will crash.</p><pre><strong>class </strong>DumbDog <strong>extends </strong>Animal {<br>    @Override<br>    <strong>public void </strong>makeNoise() {<br>        <strong>throw new </strong>RuntimeException(<strong>&quot;I can&#39;t make noise&quot;</strong>);<br>    }<br>}</pre><p>If we take Android example then we should write the custom RecyclerView adapter class in such a way that it still works with RecyclerView. We should not write something which will lead the RecyclerView to misbehave.</p><blockquote><strong>I — Interface Segregation Principle</strong></blockquote><p>This principle suggests that “many client specific interfaces are better than one general interface”. This is the first principle which is applied on interface, all the above three principles applies on classes. Let’s take following example to understand this principle.</p><p>In android we have multiple click listeners like OnClickListener as well as OnLongClickListener.</p><pre><em>/**<br> * Interface definition for a callback to be invoked when a view is clicked.<br> */<br></em>public interface OnClickListener {<br>    <em>/**<br>     * Called when a view has been clicked.<br>     *<br>     * </em><strong><em>@param </em></strong><em>v The view that was clicked.<br>     */<br>    </em>void onClick(View v);<br>}</pre><pre><em>/**<br> * Interface definition for a callback to be invoked when a view has been clicked and held.<br> */<br></em>public interface OnLongClickListener {<br>    <em>/**<br>     * Called when a view has been clicked and held.<br>     *<br>     * </em><strong><em>@param </em></strong><em>v The view that was clicked and held.<br>     *<br>     * </em><strong><em>@return </em></strong><em>true if the callback consumed the long click, false otherwise.<br>     */<br>    </em>boolean onLongClick(View v);<br>}</pre><p>Why do we need two interfaces just for same action with one single tap and another with long press. Why can’t we have following interface.</p><pre>public interface MyOnClickListener {<br>    void onClick(View v);<em><br>    </em>boolean onLongClick(View v);<br>}</pre><p>If we have this interface then it will force clients to implement onLongClick even if they don’t even care about long press. Which will lead to overhead of unused methods. So having two separate interfaces helps in removing the unused methods. If any client want both behaviours then they can implement both interfaces.</p><blockquote><strong>D — Dependency Inversion Principle</strong></blockquote><p>This principle suggest that “classes should depend on abstraction but not on concretion”. What does it mean that we should be having object of interface which helps us to communicate with the concrete classes. What do we gain from this is, we hide the actual implementation of class A from the class B. So if class A changes the class B doesn’t need to care or know about the changes.</p><p>In android if we are following MVP pattern then we need to keep reference of Presenter in our View. Now if we keep the Presenter concrete class object in View then it leads to tight coupling. So what we do is we create a interface which abstracts the implementation of presenter and our view class keeps the reference of the PresenterInterface.</p><p>Thanks for reading this article. Hope you would have liked it!. <strong>Please clap, share and follow me to support.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79d1ce114ace" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/solid-principles-explained-with-examples-79d1ce114ace">SOLID Principles — explained with examples</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Restricting Access of Android Apps on Root Devices.]]></title>
            <link>https://medium.com/mindorks/restricting-access-of-android-apps-on-root-devices-ed68055c7883?source=rss-4b86b902db4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed68055c7883</guid>
            <category><![CDATA[root-android-app]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[root-android-phone]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Raj Suvariya]]></dc:creator>
            <pubDate>Sun, 04 Mar 2018 13:25:59 GMT</pubDate>
            <atom:updated>2018-03-04T13:25:59.553Z</atom:updated>
            <content:encoded><![CDATA[<p>Every developer wants to make their app as secure as possible. But while talking about Root Devices most of them fails, because in Root Devices user have access to all the files. They can read all the files and can manipulate the data. So here are some methods which can come to rescue for them. These methods can be added in the splash activity or the launcher activity and developer can check if the device is rooted or not. If device is rooted then developer can stop the app with some message to user.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/734e8fa740e8621431b25f0776a027b8/href">https://medium.com/media/734e8fa740e8621431b25f0776a027b8/href</a></iframe><p>If you find this blog useful, then claps would be appreciated. Sharing on social platforms would be more appreciated.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed68055c7883" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/restricting-access-of-android-apps-on-root-devices-ed68055c7883">Restricting Access of Android Apps on Root Devices.</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making ActionBar beautiful by showing Count on ActionBar Icon]]></title>
            <link>https://medium.com/mindorks/making-actionbar-beautiful-by-showing-count-on-actionbar-icon-ed3a3a1a74ea?source=rss-4b86b902db4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed3a3a1a74ea</guid>
            <category><![CDATA[actionbar]]></category>
            <category><![CDATA[drawables]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[notifications]]></category>
            <category><![CDATA[badges]]></category>
            <dc:creator><![CDATA[Raj Suvariya]]></dc:creator>
            <pubDate>Fri, 15 Sep 2017 17:28:45 GMT</pubDate>
            <atom:updated>2022-11-25T13:26:00.735Z</atom:updated>
            <content:encoded><![CDATA[<p>In today’s market, if you want to succeed, you not only need the great product but also need great UX (User Experience). So, in android apps whenever you have select items functionality and CTA(Call to Action) button in ActionBar then showing a count of the number of selected items on CTA Icon Button makes a great UX. Like shown in the image below, we had a create group functionality in one of the projects, so we added a count on the create group icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2KJ2Wpi3ORd0kztbzlQcXw.jpeg" /><figcaption>Group Icon with a count on it</figcaption></figure><p>There is one easy way to implement icon with a count in Android ActionBar.</p><ul><li>Create different icons for each state and add all in your project. Whenever, you need to change the count you change the icon drawable itself. This solution is costly in terms of the size as you need <strong>n</strong> drawables if the icon has <strong>n</strong> possible states, so the size would increase by (n-1)*(size of image).</li></ul><p>So, in this article we will go through other solution which is very efficient. We will use layer-list for the ActionBar icon. The bottom layer will remain same and the top layer will keep changing as count changes. We will add custom component to draw the top layer.</p><blockquote>Step 1: Creating drawable with layer-list</blockquote><p>First of all, we will understand what are layer-list and how it works? Basically layer-list provides us a way to create a drawable icon using more than one items (drawable, bitmap etc.) and adding them in each layer of layer-list stack. Whichever layer is having higher index is visible on the top others can be seen below it. In xml the index increases as we go from top item to bottom item. So the item at the bottom in xml will be visible at the top of the resulting drawable and the item at the top in xml will be visible at the bottom of the resulting drawable.</p><p>For this article we need a create group icon and a count. So we can split them in two different layers. In bottom layer we can add create group icon and in the top layer we can put count drawable. In the code below you can see that we have created a drawable with layer-list, here count item gets higher index so it will be visible on the top of the create group icon.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/606506c9e436507567ef2e2b5bcb7c4b/href">https://medium.com/media/606506c9e436507567ef2e2b5bcb7c4b/href</a></iframe><blockquote>Step 2: Adding the icon created in step 1 to menu of the ActionBar</blockquote><p>To add the drawable created above (actionbar_group_icon.xml) in Android ActionBar, we need to add it in the menu of the ActionBar.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c6850c2054d24b24fcc01ae8b8f7d99/href">https://medium.com/media/1c6850c2054d24b24fcc01ae8b8f7d99/href</a></iframe><p>As shown in the above code it is really simple to add the created drawable in menu. The menu resource file can be found at res/menu folder.</p><blockquote>Step 3: Creating Custom Component to draw count on top layer</blockquote><p>In the following code I have created a CountDrawable by extending Drawable class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c0debb72dd42a741c3fe99b54c5ecad/href">https://medium.com/media/6c0debb72dd42a741c3fe99b54c5ecad/href</a></iframe><p><strong>Note: </strong>You must specify badge_count_textsize in your dimen.xml and background_color in your colors.xml file.</p><blockquote>Step 4: Usage</blockquote><p>To set the count on the icon, use the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/905b9418cefcc6d674d55a8598845cd4/href">https://medium.com/media/905b9418cefcc6d674d55a8598845cd4/href</a></iframe><blockquote>And you’re done!</blockquote><p>Viola!! You have created an awesome icon with count for your ActionBar.</p><p><strong>Note: </strong>In this article I have used the count drawable for ActionBar only, but the use is not restricted for ActionBar only. You can apply this drawable anywhere on the screen.</p><p>Please clap for this article to show your support and help me to reach out to larger audience. Please follow me to get future updates about my blogs.</p><p>In case of any queries comment below or drop me an email on rajsuvariya@gmail.com.</p><p>Also, if you want to get email notifications then please submit your email id in the form below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F2acca1%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2F2acca1%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d35b01592f932f0fc2b1756c210d0a1/href">https://medium.com/media/0d35b01592f932f0fc2b1756c210d0a1/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed3a3a1a74ea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/making-actionbar-beautiful-by-showing-count-on-actionbar-icon-ed3a3a1a74ea">Making ActionBar beautiful by showing Count on ActionBar Icon</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Native Modules in React Native + Android - Hybrid Apps]]></title>
            <link>https://medium.com/mindorks/how-to-use-native-modules-in-react-native-android-hybrid-apps-62b67a2cc7ca?source=rss-4b86b902db4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/62b67a2cc7ca</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[hybrid-apps]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Raj Suvariya]]></dc:creator>
            <pubDate>Sun, 06 Aug 2017 07:32:58 GMT</pubDate>
            <atom:updated>2022-11-25T13:25:29.964Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QbwV0zFemiRih1u1T_fMVw.jpeg" /></figure><p>Well, when you are developing hybrid apps (React Native for some modules and native android for rest of the module) then you must have came up with this situation that How can I use the native android functionality / classes like SharedPreference or Utilities class etc ?</p><p>Well, It is really simple with Native Module. You can write your own app specific Native Modules. In this blog we will learn how to create one. For this blog our aim would be to access SharedPreference of Native Android app.</p><p>Before getting started please make sure that you have the following setup ready in your computer.<br>1. Android Studio<br>2. React Native setup<br>3. An existing hybrid (React Native + Android) project</p><p>If you have existing project only in native Android then follow this blog to setup the React Native.</p><p><a href="https://medium.com/@rajsuvariya/react-native-integration-with-existing-app-f2757c2e672d">Integrating React Native with existing Android app</a></p><blockquote>Step 1 : Create the module</blockquote><p>In your Android Studio, create a new Java file <strong>SharedPrefereneModule.java </strong>at your convenient path and extend it with <strong>ReactContextBaseJavaModule. </strong>There is a one abstract method <strong>getName() </strong>of this super class which you need to override. This method returns name of the module by which you can access it from React Native. Also, you need a constructor with React Application Context.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae49374a09b930480efde78db755e8b9/href">https://medium.com/media/ae49374a09b930480efde78db755e8b9/href</a></iframe><p>Here, we have also created an instance of AppSharedPreferenceManager (a class which handles shared preferences) which we will need in next steps.</p><p>Note: If you don’t want to do SharedPreference operations in other class then you can simply create SharedPreference instance instead here of AppSharedPreferenceManager.</p><blockquote>Step 2: Create the packager</blockquote><p>Now we need packager to provide this module to React Instance Manager, so Create a new java file <strong>SharedPreferencePackager.java</strong> at your convenient path and extend it with <strong>ReactPackage</strong>. This class has three abstract methods which we need to override. See the following code for it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91d72b9348f946e8c2bef8f8f34712c2/href">https://medium.com/media/91d72b9348f946e8c2bef8f8f34712c2/href</a></iframe><p>Here, we have added <strong>SharedPrefereneModule </strong>which we created in first step to Native Module list. This packager can also be used for Native Ui Components and JS modules, but in this blog we are only focusing on Native Modules so we are returning empty list in other two methods.</p><blockquote>Step 3 : Add package to React Instance Manager</blockquote><p>As we have created the SharePreferencePackager now we are ready to add it in React Instance Manager. To do so open your ReactActivity and find the reactInstanceManager initialization and add SharePreferencePackager.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89ffb4805f42a8ae55e4fed26ae431ac/href">https://medium.com/media/89ffb4805f42a8ae55e4fed26ae431ac/href</a></iframe><p>This react instance manager you won’t be able to find if you have created project using react-native init . In that case you need to add this package inside getPackages() method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd0304957f847cda1e37cf0ded64be6e/href">https://medium.com/media/fd0304957f847cda1e37cf0ded64be6e/href</a></iframe><blockquote>Step 4: Add methods and usage</blockquote><p>Now we are ready with the Native Module. We need to create methods which can read and write the SharedPreference of native android. So open the SharedPreferenceModule.java created in step 1. Add the methods required for your application with a @ReactMethod annotation. Here is a one sample method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b5801fa02b1bdb0c6fcd12d3bf4821f/href">https://medium.com/media/1b5801fa02b1bdb0c6fcd12d3bf4821f/href</a></iframe><p>You must be worried about two thing in the above method.<br>1. Return type is void<br>2. What the hack is Callback?</p><p>So, one thing you need to understand is that you are calling this methods from React Native so you cannot simply return anything just by changing the return type from void to something like String or int or boolean. For the native Android to React Native communication the Callbacks are used. Callback is nothing but javascript callbacks just like onTextChange of &lt;Text /&gt; tag. You can accept as many callbacks as you want in this method (like successCallback, failureCallback etc.). When you have data you can invoke the callback and the rest will be handled by JS.</p><p>Here is the code snippet in React Native to use the created Native Module. As you see here we are passing one callback. When we have mpin ready at Java side we will invoke the callback and the JS console will print this mpin.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48762ec0622ef00fa14bfe19eb118c38/href">https://medium.com/media/48762ec0622ef00fa14bfe19eb118c38/href</a></iframe><p>If you like this blog please click on heart ❤ to support me for reaching as many people as I can. In case of any queries you can comment below or drop an email on <a href="http://rajsuvariya@gmail.com/">rajsuvariya@gmail.com</a>.</p><p><strong>Next, I will be writing blog on using Android Native views inside React Native. Follow me and stay tuned.</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F2acca1%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2F2acca1%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d35b01592f932f0fc2b1756c210d0a1/href">https://medium.com/media/0d35b01592f932f0fc2b1756c210d0a1/href</a></iframe><p>#ReactNative #Android #NativeModules #HybridApps</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62b67a2cc7ca" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/how-to-use-native-modules-in-react-native-android-hybrid-apps-62b67a2cc7ca">How to use Native Modules in React Native + Android - Hybrid Apps</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating React Native with existing Android app]]></title>
            <link>https://medium.com/mindorks/react-native-integration-with-existing-app-f2757c2e672d?source=rss-4b86b902db4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2757c2e672d</guid>
            <category><![CDATA[hybrid-apps]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Raj Suvariya]]></dc:creator>
            <pubDate>Mon, 10 Jul 2017 18:02:24 GMT</pubDate>
            <atom:updated>2017-08-28T17:03:31.995Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lFFK0SbWJcWQtq3P.png" /></figure><p><strong>Note : </strong>This article has been written after testing under the following environment. <br>1) React version : 16.0.0-alpha.12<br>2) React Native version : ^0.46.1<br>The guide might change with the version change. So if this guide doesn’t work for your environment please mention the errors in the comments below or send me a mail on rajsuvariya@gmail.com</p><blockquote><strong>Pre-requisite:</strong></blockquote><ol><li>React Native setup in your system. If you don’t have then please follow this <a href="https://facebook.github.io/react-native/docs/getting-started.html">guide</a>. <br><strong>Note : </strong>Please do not proceed if you are not able to create and run a project without any errors with the above guide.</li><li>Android Studio setup with the latest version of JDK.</li><li>An existing Android project ( for this article we will be using <strong>AwesomeApp</strong> ).</li></ol><blockquote><strong>Step 1 : Re-structuring the existing project</strong></blockquote><p>This step is not the mandatory step for integrating react native into the existing project. But this step is important as it separates the Android Native and React Native code from each other.</p><p>Create a folder <strong>/android<em> </em></strong>inside the root directory of the existing project ( in AwesomeApp folder).</p><p>After this step, your structure looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2ygU9FgwHz1sw1Il.jpg" /><figcaption>android folder created in root project folder</figcaption></figure><p>Now move everything to the android folder using cut and paste. So the existing project files will live at the path <strong><em>/AwesomeApp/android/&lt;project files&gt;</em></strong><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o493zNzAf-woCIyL.jpg" /><figcaption>Project structure after moving everything to <strong>/android </strong>folder</figcaption></figure><p>Now, you can open <strong><em>/AwesomeApp/android </em></strong>in <em>Android Studio </em>to write the Android Native code.</p><blockquote><strong>Step 2 : Install JavaScript dependencies</strong></blockquote><p>Now, move back to root directory <strong><em>/AwesomeApp</em></strong> and create a file named <strong>package.json </strong>and paste the following code inside it.</p><pre>{<br>  &quot;name&quot;: &quot;AwesomeReactApp&quot;,  //name of your react app<br>  &quot;version&quot;: &quot;0.0.1&quot;,<br>  &quot;private&quot;: <strong>true</strong>,<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;node node_modules/react-native/local-cli/cli.js start&quot;<br>  }<br>}</pre><p>It’s time to install the <strong>react</strong> and <strong>react-native </strong>packages in our project. So, open a terminal inside the root directory <strong><em>/AwesomeApp </em></strong>and run the following command.</p><pre>$ npm install --save react@16.0.0-alpha.12 react-native</pre><p>This will create a new <strong><em>/node_modules </em></strong>folder inside the root directory. This folder contains all the javascript packages required to run the app.</p><blockquote><strong>Step 3 : Integrating React Native in the project</strong></blockquote><p>Open the <strong><em>AwesomeApp/android </em></strong>folder in Android Studio.</p><h4>Configuring Maven</h4><p>Add the following dependency to the <strong><em>/app/build.gradle</em> </strong>of the existing project.</p><pre>$ compile &quot;com.facebook.react:react-native:+&quot;</pre><p>If you want to work with the specific version of the react native then replace the + with the exact version.</p><p>Add an entry for the local React Native maven directory to <strong><em>build.gradle</em></strong>. Be sure to add it to the &quot;allprojects&quot; block and add it to <strong><em>android/build.gradle,</em></strong> not to <strong><em>android/app/build.gradle</em></strong></p><pre>maven {<br>    url &quot;<em>&lt;PATH TO YOUR ROOT DIRECTORY&gt;</em>/AwesomeApp/node_modules/react-native/android&quot;<br>}</pre><p>So, the <strong><em>android/build.gradle </em></strong>looks like this now.</p><pre>allprojects {<br>    repositories {<br>        jcenter()<br>        maven { url &#39;https://maven.google.com&#39; }<br><strong>        maven {<br>            url &quot;/home/user/Workspace/react-native-projects/AwesomeApp/node_modules/react-native/android&quot;<br>        }</strong><br>    }<br>}</pre><p>Now, sync the project in Android Studio. If you get any error please resolve it before proceeding to next step.</p><h4>Adding permissions</h4><p>Open <strong><em>AndroidManifest.xml </em></strong>in Android Studio which can be located at path <em>android/app/src/main/AndroidManifest.xml. </em>Add the following permission to it.</p><pre>&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;</pre><p>After adding the permission, AndroidManifest.xml looks like this</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br>&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    package=&quot;com.rajsuvariya.awesomeapp&quot;&gt;<br><br><strong>    &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;<br></strong>    <br>    &lt;application<br>        android:name=&quot;.IfaApp&quot;<br>        android:allowBackup=&quot;true&quot;<br>        ...</pre><p>If you want to access <em>DevSettingsActivity </em>(used to access developer settings from mobile app)<em> </em>then add it to AndroidManifest.xml</p><pre>&lt;activity android:name=&quot;com.facebook.react.devsupport.DevSettingsActivity&quot; /&gt;</pre><p>This is only really used in dev mode when reloading JavaScript from the development server,<em> so you can strip this in release builds if you need to.</em></p><h4>Code Integration</h4><p>Now, we will add the React Native code and create an activity in native Android which will render the React Native code.</p><p>Create <strong>index.android.js</strong> file inside the root directory <em>/AwesomeApp. </em>This is the entry point of the React Native app. You can read about it more on React Native official documentation. We will be adding a very simple code in React Native which will just say “Hey! How are you?” to the user.</p><p>Add the following code inside index.android.js</p><pre>import React from &#39;react&#39;;<br>import {<br>  AppRegistry,<br>  StyleSheet,<br>  Text,<br>  View<br>} from &#39;react-native&#39;;<br><br>class HelloUser extends React.Component {<br>  render() {<br>    return (<br>      &lt;View style={styles.container}&gt;<br>        &lt;Text style={styles.hello}&gt;Hey! How are you?&lt;/Text&gt;<br>      &lt;/View&gt;<br>    )<br>  }<br>}<br>var styles = StyleSheet.create({<br>  container: {<br>    flex: 1,<br>    justifyContent: &#39;center&#39;,<br>  },<br>  hello: {<br>    fontSize: 20,<br>    textAlign: &#39;center&#39;,<br>    margin: 10,<br>  },<br>});<br><br>AppRegistry.registerComponent(&#39;AwesomeReactApp&#39;, () =&gt; HelloUser);</pre><p>Make sure you write the same project name in AppRegistry.registerComponent() as written in package.json.</p><p>If you are targeting Android <strong>API level ≥ 23 </strong>then you need to take a permission from user for opening the React Native app from your native Android app, as after API level 23 new dynamic permission for opening other apps has been introduced.</p><p>For requesting the permission add the following code either inside the onCreate() of the first activity of the app or inside the onCreate() of the activity which will open the React Native activity.</p><pre>if (Build.VERSION.<em>SDK_INT </em>&gt;= Build.VERSION_CODES.<em>M</em>) {<br>    if (!Settings.<em>canDrawOverlays</em>(this)) {<br>        Intent intent = new Intent(Settings.<em>ACTION_MANAGE_OVERLAY_PERMISSION</em>,<br>                Uri.<em>parse</em>(&quot;package:&quot; + getPackageName()));<br>        startActivityForResult(intent, <em>OVERLAY_PERMISSION_REQ_CODE</em>);<br>    }<br>}</pre><p>After adding this permission request, the onCreate() looks like this.</p><pre>private static final int <em>OVERLAY_PERMISSION_REQ_CODE </em>= 1212;</pre><pre>@Override<br>protected void onCreate(Bundle savedInstanceState) {<br>    super.onCreate(savedInstanceState);<br>        ...<br> <strong>       if (Build.VERSION.<em>SDK_INT </em>&gt;= Build.VERSION_CODES.<em>M</em>) {<br>            if (!Settings.<em>canDrawOverlays</em>(this)) {<br>                Intent intent = new Intent(Settings.<em>ACTION_MANAGE_OVERLAY_PERMISSION</em>,<br>                        Uri.<em>parse</em>(&quot;package:&quot; + getPackageName()));<br>                startActivityForResult(intent, <em>OVERLAY_PERMISSION_REQ_CODE</em>);<br>            }<br>        }<br></strong>        ...</pre><pre>}</pre><p>Finally, the onActivityResult() method (as shown in the code below) has to be overridden to handle the permission Acceptance or Denial from the user.</p><pre>@Override<br>protected void onActivityResult(int requestCode, int resultCode, Intent data) {<br>    if (requestCode == <em>OVERLAY_PERMISSION_REQ_CODE</em>) {<br>        if (Build.VERSION.<em>SDK_INT </em>&gt;= Build.VERSION_CODES.<em>M</em>) {<br>            if (!Settings.<em>canDrawOverlays</em>(this)) {<br>                Toast.<em>makeText</em>(this, &quot;You cannot open the React Native app as you have denied the permission&quot;, Toast.<em>LENGTH_SHORT</em>).show();<br>            }<br>        }<br>    }<br>}</pre><p>Now, we will write the <strong>MyReactActivity</strong> which will render the React Native App. So, create a new Activity <strong>MyReactActivity</strong> using Android Studio and add the following code inside it.</p><pre>public class MyReactActivity extends Activity implements DefaultHardwareBackBtnHandler {<br>    private ReactRootView mReactRootView;<br>    private ReactInstanceManager mReactInstanceManager;<br><br>    @Override<br>    protected void onCreate(Bundle savedInstanceState) {<br>        super.onCreate(savedInstanceState);<br><br>        mReactRootView = new ReactRootView(this);<br>        mReactInstanceManager = ReactInstanceManager.<em>builder</em>()<br>                .setApplication(getApplication())<br>                .setBundleAssetName(&quot;index.android.bundle&quot;)<br>                .setJSMainModuleName(&quot;index.android&quot;)<br>                .addPackage(new MainReactPackage())<br>                .setUseDeveloperSupport(BuildConfig.<em>DEBUG</em>)<br>                .setInitialLifecycleState(LifecycleState.<em>RESUMED</em>)<br>                .build();<br>        mReactRootView.startReactApplication(mReactInstanceManager, &quot;AwesomeReactApp&quot;, null);<br><br>        setContentView(mReactRootView);<br>    }<br><br>    @Override<br>    public void invokeDefaultOnBackPressed() {<br>        super.onBackPressed();<br>    }<br><br>    @Override<br>    protected void onPause() {<br>        super.onPause();<br><br>        if (mReactInstanceManager != null) {<br>            mReactInstanceManager.onHostPause(this);<br>        }<br>    }<br><br>    @Override<br>    protected void onResume() {<br>        super.onResume();<br><br>        if (mReactInstanceManager != null) {<br>            mReactInstanceManager.onHostResume(this, this);<br>        }<br>    }<br><br>    @Override<br>    protected void onDestroy() {<br>        super.onDestroy();<br><br>        if (mReactInstanceManager != null) {<br>            mReactInstanceManager.onHostDestroy(this);<br>        }<br>    }<br><br>    @Override<br>    public void onBackPressed() {<br>        if (mReactInstanceManager != null) {<br>            mReactInstanceManager.onBackPressed();<br>        } else {<br>            super.onBackPressed();<br>        }<br>    }<br><br>    @Override<br>    public boolean onKeyUp(int keyCode, KeyEvent event) {<br>        if (keyCode == KeyEvent.<em>KEYCODE_MENU </em>&amp;&amp; mReactInstanceManager != null) {<br>            mReactInstanceManager.showDevOptionsDialog();<br>            return true;<br>        }<br>        return super.onKeyUp(keyCode, event);<br>    }<br><br>}</pre><p>You will get a lot of errors after pasting this code inside MyReactActivity, as the packages used inside the activity are not imported. To import all the packages hover over them one by one and press Alt + Enter. Make sure you import BuidConfig from your package and not from ...facebook...package.</p><p>Also, change the theme of this activity as some of the components use this special theme. So, inside the AndroidManifest.xml update/add the following code.</p><pre>&lt;activity<br>  android:name=”.react.MyReactActivity” <br>  android:label=”@string/app_name”  <br>  android:theme=”@style/Theme.AppCompat.Light.NoActionBar”&gt;&lt;/activity&gt;</pre><h4>Opening React App</h4><p>We need to open the MyReactNative activity to launch the React Native app. To do so write the following code wherever you want (according to the business logic of your app)</p><pre>Intent intent = new Intent(this, MyReactActivity.class);<br>startActivity(intent);</pre><h4>Run and Test</h4><p>We are ready to run the app and test it out. To start the React Native server run the following command inside the root directory <strong><em>/AwesomeApp</em></strong>.</p><pre>$ npm start</pre><p>Now, run the app from Android Studio as usual and test it out. You must see this screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/0*vEjZof8Ymi6K8hqZ.png" /></figure><p>Mark ❤ if you like this blog and follow me to get notification of my future blogs on React Native and Android.</p><p>My other blog(s) on ReactNative:</p><p><a href="https://medium.com/@rajsuvariya/how-to-use-native-modules-in-react-native-android-hybrid-apps-62b67a2cc7ca">How to use Native Modules in React Native + Android - Hybrid Apps</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F2acca1%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2F2acca1%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d35b01592f932f0fc2b1756c210d0a1/href">https://medium.com/media/0d35b01592f932f0fc2b1756c210d0a1/href</a></iframe><p>#ReactNative #Android #HybridApps</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2757c2e672d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/react-native-integration-with-existing-app-f2757c2e672d">Integrating React Native with existing Android app</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Activity Back Stack and Launch Mode Part -2]]></title>
            <link>https://medium.com/wiselteach/activity-back-stack-and-launch-mode-part-2-e715c724f7cf?source=rss-4b86b902db4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e715c724f7cf</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[backstack]]></category>
            <category><![CDATA[launch-mode]]></category>
            <dc:creator><![CDATA[Raj Suvariya]]></dc:creator>
            <pubDate>Tue, 18 Apr 2017 14:30:13 GMT</pubDate>
            <atom:updated>2017-08-28T17:04:22.607Z</atom:updated>
            <content:encoded><![CDATA[<p>In the first part we learned about activity backstack and two launch modes of Activity. If you haven’t read the first part then do it now and come back when you are done.</p><p><a href="https://medium.com/wiselteach/activity-back-stack-and-launch-mode-part-1-693130682120">Activity Back Stack and Launch Mode Part -1</a></p><p>In this second part we will learn about two more Activity launchmodes : SingleTask and SingleInstance.</p><blockquote>SingleTask</blockquote><p><em>Definition as per Android Docs:<br>“</em>The system creates the activity at the root of a new task and routes the intent to it. However, if an instance of the activity already exists, the system routes the intent to existing instance through a call to its <a href="https://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)">onNewIntent()</a> method, rather than creating a new one.”</p><p>What does it mean is only one instance of any activity can exist through all the tasks of the application. If there is already one instance sitting on back stack of any task inside the application and we call startActivity() then all the activities above that instance from the particular task’s backstack will be removed and that task and the activity instance will become visible on the screen.</p><p>For ex.<br>Suppose, there are 4 activities A,B,C and D. C has launchmode SingleTask and the present application backstack is shown at top of the image. Now if we call startActivity(c) then the backstack would became like shown at bottom of the image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*flh5KQBitMQHtPLa2roqRA.jpeg" /></figure><blockquote><strong>Note: In the Android docs definition it is mentioned “The system creates the activity at the root of a new task and routes the intent to it”.</strong> However this holds only true when the activity having launchmode as SingleTask also has different taskAffinity then application. If it has the taskAffinity matching any other task inside the application then the new instance will be pushed on the top of the back stack as usual.</blockquote><p>You might have question that “How to change the content from the previous instance?”. Well, you can override the <a href="https://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)">onNewIntent()</a> method of the Activity to get new intent and update the information on the screen.</p><blockquote>SingleInstance</blockquote><p><em>Definition as per Android Docs:<br>“</em>Same as “singleTask&quot;, except that the system doesn&#39;t launch any other activities into the task holding the instance. The activity is always the single and only member of its task”.</p><p>It’s pretty clear from the definition itself that it is just like the SingleTask except the activity will be created as the root of the new task regardless of the taskAffinity and that task cannot contain any more activity instance. So the task will contain only one activity instance with launchmode as SingleInstance.</p><p>If we navigate to any other activity from the SingleInstance activity it takes us back to previous task and performs the new activity creation as per it’s launch mode on that task.</p><p>Also, in the case of SingleInstance even if there are more than one task we can only see one instance in recent apps.</p><p>Here is the comparison of all the launchmodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*N2jfgErutZerHpu1Dq9aKg.gif" /></figure><p>If you want to play around by changing the launchmodes of the activities you can get the starter code here.</p><p><a href="https://github.com/AnilDeshpande/ActivityLauchModesDemo">AnilDeshpande/ActivityLauchModesDemo</a></p><p>If you like the blog please mark ❤ and also share it with your fellow developer. Also subscribe to our newsletter to get notifications about ourupcoming blogs.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F2acca1%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2F2acca1%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d35b01592f932f0fc2b1756c210d0a1/href">https://medium.com/media/0d35b01592f932f0fc2b1756c210d0a1/href</a></iframe><p><a href="http://www.wiselteach.com/">www.wiselteach.com</a></p><p>#AndroidMonk</p><p>#WiseL #WiseLTeach</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e715c724f7cf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wiselteach/activity-back-stack-and-launch-mode-part-2-e715c724f7cf">Activity Back Stack and Launch Mode Part -2</a> was originally published in <a href="https://medium.com/wiselteach">WiseLTeach</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Activity Back Stack and Launch Mode Part -1]]></title>
            <link>https://medium.com/wiselteach/activity-back-stack-and-launch-mode-part-1-693130682120?source=rss-4b86b902db4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/693130682120</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[backstack]]></category>
            <category><![CDATA[launch-mode]]></category>
            <dc:creator><![CDATA[Raj Suvariya]]></dc:creator>
            <pubDate>Thu, 06 Apr 2017 19:13:38 GMT</pubDate>
            <atom:updated>2017-07-27T14:11:36.823Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wondered what happens to the current activity when you navigate to some other activity by taping some view on the screen? When you press back button how suddenly the same activity comes in font of you? If yes, then you are at the right place to get the answer about these kind of questions. In this blog we will learn about the activity back stack and launch mode of the activity. The blog is divided into 2 parts.</p><p><strong>Knowledge before you read this blog<br></strong>Every application has one or more <strong><em>tasks</em></strong>. Each task is differentiated by the <strong><em>task affinity</em></strong> which is unique for every task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JA0wRAhkhdzMQgQXHIvbQQ.jpeg" /></figure><p>Application by default has only one task with task affinity equal to package name which can be found in androidmanifest.xml</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/0*LFRHIJSSA3ndcFwU.jpg" /></figure><p>To see, how many tasks a application has, you can just open recent-apps of your device and just count the number of instances of the same app, that is the number of tasks the app has.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*Qy6zmmbUF9HFbrM5HsrWdg.png" /></figure><blockquote><strong>Note:</strong> Generally, there will be only one task in your application, and which is the best way of writing your application. You should only create more than one task when it is exceptionally necessary. Like payment gateway page, which you want to keep unaffected by other tasks.</blockquote><p><strong>Activity Back Stack<br></strong>The name itself suggest that it has something to do with stack of activities. As we discussed above every activity has either one or more tasks. For each task there is exactly one activity back stack. The topmost activity on the task’s back stack is visible on the screen. Usually, when the app launches the app has one task with just one activity (MainActivity) on it’s backstack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PmUOlz7C5ViLk__6cBjHtA.jpeg" /></figure><p>Whenever, the user navigates from one activity to another the new activity is pushed on the top of the visible task’s back stack and it gets visible to the user, hiding the previous activity’s instance underneath. When user presses back the topmost activity is popped from the visible task’s backstack and the next activity in that stack gets visible on the screen.</p><p>This isn’t just limited to activities, even fragments can be pushed to the backstack. While navigating away from the fragment you can just add</p><pre>fragment_transaction.addBackStack();</pre><p>so when you press back the previous fragment gets visible on the screen.</p><p><strong>Note: </strong>I have used “visible task” term in above discussion. What it means is that there might be lot of task but you can see only one on the screen so the one which is being showed to you is visible task.</p><p><strong>Launch Modes<br></strong>Again name itself suggest that it has something to do with how activity gets launched when we call startActivity(intent) or similar functions. There are basically four type of the launch modes.</p><ol><li>Standard</li><li>SingleTop</li><li>Single Task</li><li>Single Instance</li></ol><blockquote>Standard</blockquote><p><em>Definition as per Android Docs:<br>“The system always creates a new instance of the activity in the target task and routes the intent to it.”</em></p><p>Standard launch mode is default in all the activities you create in your android application. In this launch mode no matter what is there in activity back stack the new instance of the new activity gets created when we pass the intent of the new activity.</p><p>For example: Suppose you have very simple app with just one activity named MainActivity and only one button on the main activity. Now if you call start activity with intent of MainActivity on click of the button then it will launch the new instance of same activity again and the current instance will go to back stack. If you click the button 10 times then there will be 10 instances of the activity in the back stack. So you need to press back 10 times to get out of your application.</p><blockquote>SingleTop</blockquote><p><em>Definition as per Android Docs:<br>“</em>If an instance of the activity already exists at the top of the target task, the system routes the intent to that instance through a call to its <a href="https://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)">onNewIntent()</a> method, rather than creating a new instance of the activity.<em>”</em></p><p>Which means that if we call startActivity with the intent of same activity which is on the top of back stack then the new instance will not be created rather the intent will be passed to activity via a method <a href="https://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)">onNewIntent()</a>.</p><p>Taking the same example as above: Suppose you have very simple app with just one activity named MainActivity and only one button on the main activity. Now if the launch mode of the main activity is single top then if you click on the button which call startActivity with the intent of MainActivity then also it won’t launch new instance of the MainActivity because the instance on the top of the backstack is of MainActivity. So you can prevent users from opening new instance of same activity which is visible on the screen.</p><p>That’s all for part 1, To learn about SingleTask and SingleInstance checkout the part 2 of this blog.</p><p><a href="https://medium.com/wiselteach/activity-back-stack-and-launch-mode-part-2-e715c724f7cf">Activity Back Stack and Launch Mode Part -2</a></p><p>Please mark ❤ if you like the blog. In case if you find any mistake please mention that in comment. Stay tuned for more tech blogs.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F2acca1%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2F2acca1%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/34afc03fc364a74f43446ac79eafff71/href">https://medium.com/media/34afc03fc364a74f43446ac79eafff71/href</a></iframe><p><a href="http://www.wiselteach.com/">www.wiselteach.com</a></p><p>#AndroidMonk</p><p>#WiseL #WiseLTeach</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=693130682120" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wiselteach/activity-back-stack-and-launch-mode-part-1-693130682120">Activity Back Stack and Launch Mode Part -1</a> was originally published in <a href="https://medium.com/wiselteach">WiseLTeach</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DiffUtils : Improving performance of RecyclerView]]></title>
            <link>https://medium.com/mindorks/diffutils-improving-performance-of-recyclerview-102b254a9e4a?source=rss-4b86b902db4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/102b254a9e4a</guid>
            <category><![CDATA[performance-improvement]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[recyclerview]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Raj Suvariya]]></dc:creator>
            <pubDate>Tue, 21 Feb 2017 18:48:59 GMT</pubDate>
            <atom:updated>2022-11-25T13:14:27.477Z</atom:updated>
            <content:encoded><![CDATA[<p>You all must have started using recyclerview instead of listview to improve the performance of the app. If you haven’t please go through our recyclerview tutorial first …</p><ul><li><a href="https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html">RecyclerView | Android Developers</a></li><li><a href="https://medium.com/wiselteach/recyclerview-in-android-androidmonk-e45b96dec0b7">RecyclerView in Android @AndroidMonk</a></li></ul><h4><strong>Difference between listview and recyclerview</strong></h4><p>Well, recyclerview is a just improved version of Listview. In ListView, if you don’t create viewholder class then it creates views for all the rows, which is not good for the performance of the app as it takes more time as well as more memory. In recyclerview creating viewholder is a must, so that only a few views are needed to show the data and it can be recycled when and where needed. As shown in the below image when we swipe up and there are no views left at the bottom then the top most view will be reused by updating its data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*yVuye_4Sx2Y24pVOp0By5A.png" /></figure><h3>RecyclerView can be improved further</h3><p>Yes! you heard it right. We use recyclerview because it doesn’t create views for all the rows, instead, it creates views that can fill up the screen and few above and below, and just recycles it. But, RecyclerView can be further improved when it comes to change the existing data of the list. For example your WhatsApp contact list, when someone changes their status you convey the data change message using the following traditional method of RecyclerView and it updates the data of RecyclerView.</p><pre>adapter.notifyDataSetChanged();</pre><h4>Then What’s the problem?</h4><p>When we use notifyDataSetChanged() method it updates all the view (all visible view on screen and few buffer view above and below the screen). It’s inappropriate way of updating list if just a few rows have changed. For example, your friend changes the status on WhatsApp then only that row should be updated instead of all the rows.</p><h4>How?</h4><p>Android has provided a class called DiffUtil under version 7 support utils. As per android documentation, the definition of DiffUtil is as follow</p><blockquote>DiffUtil is a utility class that can calculate the difference between two lists and output a list of update operations that converts the first list into the second one.</blockquote><h4>That’s enough of theory! It’s Code time</h4><p>Download or clone the following repository from github. Where I have provided a pre-built template as well as complete code. In the template, I have implemented recyclerview of contacts list and also added TODOs with numbers. In the rest of the tutorial, we will start with the template and implement all the TODOs and reach to the complete working code.</p><p><a href="https://github.com/rajsuvariya/DiffUtilsRecyclerview">GitHub - rajsuvariya/DiffUtilsRecyclerview</a></p><blockquote>TODO (1): add a SwipeRefreshLayout and wrap RecyclerView inside it</blockquote><p>Open <strong>activity_main.xml. </strong>Add <strong>SwipeRefreshLayout </strong>and wrap recyclerview inside it as follow:</p><pre>&lt;<strong>android.support.v4.widget.SwipeRefreshLayout<br>    android:id=&quot;@+id/swipeRefreshLayout&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;</strong>&gt;<br><br>    &lt;<strong>android.support.v7.widget.RecyclerView<br>        android:id=&quot;@+id/rv_main&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;match_parent&quot;<br>        android:scrollbars=&quot;vertical&quot;</strong>/&gt;<br><br>&lt;/<strong>android.support.v4.widget.SwipeRefreshLayout</strong>&gt;</pre><blockquote>TODO (2): bind xml SwipeRefreshLayout with java objects</blockquote><p>Open <strong>MainActivity.java. </strong>We need to bind the SwipeRefreshLayout in xml with the java object. Here’s the code.</p><pre><strong>public class </strong>MainActivity <strong>extends </strong>AppCompatActivity {<br>    ...<br>    SwipeRefreshLayout <strong>swipeRefreshLayout</strong>;<br><br>    @Override<br>    <strong>protected void </strong>onCreate(Bundle savedInstanceState) {<br>        <strong>super</strong>.onCreate(savedInstanceState);<br>        setContentView(R.layout.<strong><em>activity_main</em></strong>);<br><br>        <em>// </em><strong><em>TODO(2): bind xml SwipeRefreshLayout with java objects<br><br>        </em>swipeRefreshLayout </strong>= (SwipeRefreshLayout) findViewById(R.id.<strong><em>swipeRefreshLayout</em></strong>);<strong><em><br>        ...<br></em></strong>    }<br>}</pre><blockquote>TODO (3): writeCompareTo method</blockquote><p>Open <strong>Model/Contact.java. </strong>This is contact object class. We have implemented Comparable interface to compare two Contact objects. As we have implemented Comparable interface we need to implement the unimplemented method compareTo(Object 0).</p><pre>@Override<br><strong>public int </strong>compareTo(Object o) {<br>    Contact compare = (Contact) o;<br><br>    <strong>if </strong>(compare.getName().equals(<strong>this</strong>.<strong>name</strong>) &amp;&amp; compare.getPhonenumber().equals(<strong>this</strong>.<strong>phonenumber</strong>)){<br>        <strong>return </strong>0;<br>    }<br>    <strong>return </strong>1;<br>}</pre><blockquote>TODO (4): write your DiffUtilCallBack class</blockquote><p>Open<strong> Utils/MyDiffUtilCallback.java. </strong>Now, extend it with <strong>DiffUtil.Callback </strong>and ovride these 5 methods</p><ol><li>getOldListSize() : return the size of old list</li><li>getNewListSize() : return the size of new list</li><li>areItemsTheSame() : return true if the two items are same</li><li>areContentsTheSame() : return true if content of two item is same</li><li>getChangePayload() : return the difference between two items</li></ol><p>Like this…</p><pre><strong>public class </strong>MyDiffUtilCallback <strong>extends </strong>DiffUtil.Callback {<br>    ArrayList&lt;Contact&gt; <strong>newList</strong>;<br>    ArrayList&lt;Contact&gt; <strong>oldList</strong>;<br><br>    <strong>public </strong>MyDiffUtilCallback(ArrayList&lt;Contact&gt; newList, ArrayList&lt;Contact&gt; oldList) {<br>        <strong>this</strong>.<strong>newList </strong>= newList;<br>        <strong>this</strong>.<strong>oldList </strong>= oldList;<br>    }<br><br>    @Override<br>    <strong>public int </strong>getOldListSize() {<br>        <strong>return oldList </strong>!= <strong>null </strong>? <strong>oldList</strong>.size() : 0 ;<br>    }<br><br>    @Override<br>    <strong>public int </strong>getNewListSize() {<br>        <strong>return newList </strong>!= <strong>null </strong>? <strong>newList</strong>.size() : 0 ;<br>    }<br><br>    @Override<br>    <strong>public boolean </strong>areItemsTheSame(<strong>int </strong>oldItemPosition, <strong>int </strong>newItemPosition) {<br>        <strong>return true</strong>;<br>    }<br><br>    @Override<br>    <strong>public boolean </strong>areContentsTheSame(<strong>int </strong>oldItemPosition, <strong>int </strong>newItemPosition) {<br>        <strong>int </strong>result = <strong>newList</strong>.get(newItemPosition).compareTo (<strong>oldList</strong>.get(oldItemPosition));<br>        <strong>if </strong>(result==0){<br>            <strong>return true</strong>;<br>        }<br>        <strong>return false</strong>;<br>    }<br><br>    @Nullable<br>    @Override<br>    <strong>public </strong>Object getChangePayload(<strong>int </strong>oldItemPosition, <strong>int </strong>newItemPosition) {<br>        Contact newContact = <strong>newList</strong>.get(newItemPosition);<br>        Contact oldContact = <strong>oldList</strong>.get(oldItemPosition);<br><br>        Bundle diff = <strong>new </strong>Bundle();<br>        <strong>if</strong>(!newContact.getName().equals(oldContact.getName())){<br>            diff.putString(<strong>&quot;name&quot;</strong>, newContact.getName());<br>        }<br>        <strong>if</strong>(!newContact.getPhonenumber().equals (oldContact.getPhonenumber())){<br>            diff.putString(<strong>&quot;phone&quot;</strong>, newContact.getPhonenumber());<br>        }<br>        <strong>if </strong>(diff.size()==0){<br>            <strong>return null</strong>;<br>        }<br><em>        </em><strong>return </strong>diff;<br><em>    </em>}<br>}</pre><p>Here, we don’t have any key parameter to check if the items are same. So, we are always returning true which invokes areContentTheSame() for every position. In areContentTheSame() we are comparing two Contact object and checking if the names and phone numbers are the same or not. If they are not then the getChangePayload() method will be called. Where we put the difference in Bundle as key-value pairs.</p><blockquote>TODO (5): update the data</blockquote><p>Open <strong>DataFactory/DataGenerator.java. </strong>Here, we are creating a list of contacts in getData method(). After looking at the data we think that there are no mistakes, but when we look at it closely, we can see that we forgot to add “CEO” tag with “Rajat Talesra”. <em>That’s unforgivable mistake!!!</em>. So let’s update it in getUpdateData() method. Also, let’s change one contact’s phone number.</p><pre><strong>public static </strong>ArrayList&lt;Contact&gt; getUpdatedData(){<br>    ArrayList&lt;Contact&gt; contacts= <em>getData</em>();<br>    contacts.get(1).setName(<strong>&quot;Rajat Talesra (CEO)&quot;</strong>);<br>    contacts.get(0).setPhonenumber(<strong>&quot;9067250043&quot;</strong>);<br>    <strong>return </strong>contacts;<br>}</pre><blockquote>TODO (6): complete onNewData method</blockquote><p>Open <strong>Adapter/MyRecyclerViewAdapter.java. </strong>Here, we need to implement a method to let adapter know about the updated data. So complete the onNewData method by calling the MyDiffUtilCallBack class and getting the difference between old and new list and dispatching it to the adapter.</p><pre><strong>public void </strong>onNewData(ArrayList&lt;Contact&gt; newData) {<br>    DiffUtil.DiffResult diffResult = DiffUtil.<em>calculateDiff</em>(<strong>new </strong>MyDiffUtilCallback(newData, <strong>data</strong>));<br>    diffResult.dispatchUpdatesTo(<strong>this</strong>);<br>    <strong>this</strong>.<strong>data</strong>.clear();<br>    <strong>this</strong>.<strong>data</strong>.addAll(newData);<br>}</pre><p>When we call diffResult.dispatchUpdatesTo(<strong>this</strong>); it will invoke adapter’s onBindViewHolder(… , List&lt;Object&gt; payloads) method. This is the method where we take care that only those rows should be updated whose data has been changed. Let’s complete the onBindViewHolder(… , List&lt;Object&gt; payloads) method.</p><blockquote>TODO (7): complete onBindViewHolder method</blockquote><p>Open <strong>Adapter/MyRecyclerViewAdapter.java. </strong>As stated above we need to update those rows here whose data has been changed. So if the payload is empty then we will call super class’s onBindViewHolder method. If the payload is not empty then we get the bundle from the object list and based on the keys we update the specific views only. So if the name is changed then only the TextView displaying name should be updated not even entire row.</p><pre>@Override<br><strong>public void </strong>onBindViewHolder(ContactViewHolder holder, <strong>int </strong>position, List&lt;Object&gt; payloads) {<br><br>    <strong>if </strong>(payloads.isEmpty()){<br>        <strong>super</strong>.onBindViewHolder(holder, position, payloads);<br>    }<br>    <strong>else </strong>{<br>        Bundle o = (Bundle) payloads.get(0);<br>        <strong>for </strong>(String key : o.keySet()) {<br>            <strong>if</strong>(key.equals(<strong>&quot;name&quot;</strong>)){<br>                Toast.<em>makeText</em>(holder.<strong>itemView</strong>.getContext(), <strong>&quot;Contact &quot;</strong>+position+<strong>&quot; : Name Changed&quot;</strong>, Toast.<strong><em>LENGTH_SHORT</em></strong>).show();;<br>                holder.<strong>icon</strong>.setText(<strong>data</strong>.get(position).getName().substring(0,2));<br>                holder.<strong>name</strong>.setText(<strong>data</strong>.get(position).getName());<br>            }<br>            <strong>if</strong>(key.equals(<strong>&quot;phone&quot;</strong>)){<br>                Toast.<em>makeText</em>(holder.<strong>itemView</strong>.getContext(), <strong>&quot;Contact &quot;</strong>+position+<strong>&quot; : Phone Number Changed&quot;</strong>, Toast.<strong><em>LENGTH_SHORT</em></strong>).show();;<br>                holder.<strong>phonenumber</strong>.setText(<strong>data</strong>.get(position).getPhonenumber());<br>            }<br>        }<br>    }<br>}</pre><p>You must have a question that if the row’s data hasn’t been changed then the payload will be empty and the super class’s onBindViewHolder() method will be called then how we are stopping the adapter to not update all the views?</p><p>The answer is, onBindViewHolder(…, List&lt;Object&gt; payloads) gets called when the RecyclerView is getting populated very first time and only when there is a change in any row. diffResult.dispatchUpdatesTo(<strong>this</strong>) only invokes onBindViewHolder(…, List&lt;Object&gt; payloads) for those items whose data has been affected.</p><blockquote>TODO (8): setOnRefreshListener method to call adapter’s onNewData method</blockquote><p>Open<strong> MainActivity.java. </strong>Now set onRefreshListener() on swipeRefreshLayout as follow. Get the updated data and call adapter’s onNewData() method inside onRefreshListener().</p><pre><strong>swipeRefreshLayout</strong>.setOnRefreshListener(<strong>new </strong>SwipeRefreshLayout.OnRefreshListener() {<br>    @Override<br>    <strong>public void </strong>onRefresh() {<br>        <strong>adapter</strong>.onNewData(DataGenerator.<em>getUpdatedData</em>());<br>        <strong>swipeRefreshLayout</strong>.setRefreshing(<strong>false</strong>);<br>    }<br>});</pre><p>That’s all! Now, you can run the app and swipe for refreshing the list and you will see Toast messages showing what specific views were updated inside the RecyclerView.</p><p>Mark ❤ if you liked this tutorial. Also, follow us for more tutorials on Android.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F2acca1%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2F2acca1%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/34afc03fc364a74f43446ac79eafff71/href">https://medium.com/media/34afc03fc364a74f43446ac79eafff71/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=102b254a9e4a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mindorks/diffutils-improving-performance-of-recyclerview-102b254a9e4a">DiffUtils : Improving performance of RecyclerView</a> was originally published in <a href="https://medium.com/mindorks">MindOrks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>