<?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 Payal Rajput on Medium]]></title>
        <description><![CDATA[Stories by Payal Rajput on Medium]]></description>
        <link>https://medium.com/@rajputpayal1999?source=rss-54a4ef9db22b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*21NKIUeoXF7y8SoASfsvzQ.jpeg</url>
            <title>Stories by Payal Rajput on Medium</title>
            <link>https://medium.com/@rajputpayal1999?source=rss-54a4ef9db22b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 04:53:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rajputpayal1999/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[Firebase App Check with Play Integrity API in Android]]></title>
            <link>https://medium.com/simform-engineering/firebase-app-check-with-play-integrity-api-in-android-d35cf3e7eb9b?source=rss-54a4ef9db22b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d35cf3e7eb9b</guid>
            <category><![CDATA[app-integrity]]></category>
            <category><![CDATA[firebase-app-check]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[play-integrity-api]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Payal Rajput]]></dc:creator>
            <pubDate>Tue, 23 Dec 2025 07:16:44 GMT</pubDate>
            <atom:updated>2025-12-23T07:16:44.115Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cO9D09JmLOZzu3aApxwxbw.png" /><figcaption>Firebase App Check Banner</figcaption></figure><p>When we build an Android app using Firebase, we trust that only our actual app will communicate with Firebase services, such as Firestore, Realtime Database, or Cloud Storage. But in reality, anyone can extract your Firebase keys and try to access your backend using fake or modified apps.</p><p>This is where Firebase App Check comes in.</p><p><strong>In this blog, we’ll understand:</strong></p><ul><li>What is Firebase App Check?</li><li>How App Check Works?</li><li>How to integrate App Check in an Android app?</li><li>App Check Token Expiry</li><li>Common Issues That Can Break the Firebase App Check</li><li>Using App Check During Development and Debugging</li><li>App Check request metrics</li><li>How it works with Firebase services: Demo use case</li></ul><p><strong>What Is Firebase App Check?</strong></p><p>Firebase App Check is a security layer that ensures only your real, untampered app can access Firebase services.</p><p>Without App Check:</p><ul><li>Fake or cloned apps can directly access your Firestore</li><li>Automated scripts can abuse your APIs</li><li>Your Firebase quota can be drained</li><li>Your billing costs can unexpectedly increase</li></ul><p>With App Check:</p><ul><li>Firebase verifies your app before responding to requests</li><li>Only trusted and valid apps are allowed access</li><li>Modified, fake, or unauthorized apps are blocked automatically</li><li>Your data, quota, and billing stay protected</li></ul><blockquote><em>Think of App Check as an </em><strong><em>identity card</em></strong><em> your app must show before talking to Firebase.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*WASe-za9ZI7SY1Hlf8g-vg.png" /><figcaption>Firebase App Check</figcaption></figure><p><strong>How App Check Works:</strong></p><p>Firebase App Check doesn’t just blindly trust your app. Instead, it uses a trusted system called an <strong>attestation provider</strong> to verify that your app is genuine and hasn’t been tampered with. This verification process addresses three key questions: Is the app genuine, has it been modified, and was it installed from a trusted source? By checking these things, Firebase ensures that only authentic apps can communicate with its services.</p><p>On Android, the attestation provider is the <strong>Play Integrity API</strong>. This system helps confirm that user actions and server requests are coming from your real app, installed through Google Play, and running on an authentic, certified Android device. In other words, it makes sure the app interacting with Firebase is exactly the app you built, and nothing else.</p><p>How App Check Verifies Your App</p><ol><li>Your app asks the Play Integrity API for an attestation token</li><li>Play Integrity checks the app’s integrity</li><li>A token is returned to Firebase</li><li>Firebase verifies the token</li><li>If valid → access granted<br>If invalid → request blocked</li></ol><p>The best part is that all of this happens seamlessly in the background. Users won’t notice anything, but Firebase quietly ensures that every request comes from a secure, real, and untampered version of your app. This adds an invisible layer of protection, keeping your data, APIs, and backend safe from misuse.</p><p><strong>How to integrate App Check in an Android app?</strong></p><p><strong>Prerequisites:</strong> Ensure the following requirements are met before you begin:</p><ul><li>Firebase project is created</li><li>Android app has been added to Firebase</li><li>google-services.json is properly configured</li><li>Firebase SDK is already added</li></ul><p><strong>Step 1: Add App Check Dependency</strong></p><p>In your <strong>app-level</strong> build.gradle File:</p><pre>dependencies {<br>    implementation &quot;com.google.firebase:firebase-appcheck-playintegrity:LATEST_VERSION_HERE&quot;<br>}</pre><p><strong>Step 2: Enable App Check in Your App</strong></p><p>In your MainActivity or Application Class:</p><pre>val firebaseAppCheck = FirebaseAppCheck.getInstance()<br>firebaseAppCheck.installAppCheckProviderFactory(<br>    PlayIntegrityAppCheckProviderFactory.getInstance()<br>)</pre><p>That’s it! Now App Check is active in your Android app.</p><p><strong>Step 3: Enable App Check in Firebase Console</strong></p><ol><li>Open <strong>Firebase Console</strong></li><li>Go to <strong>Project Settings</strong></li><li>Open <strong>App Check</strong></li><li>Select your Android app</li><li>Enable App Check</li><li>Turn on enforcement for:</li></ol><ul><li>Firestore</li><li>Realtime Database</li><li>Cloud Storage</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4xVtT-d4eS_ciqdN93J7lg.png" /><figcaption>Enforce App Check</figcaption></figure><p>Once App Check is enabled:</p><ul><li>Firebase services will expect a <strong>valid App Check token</strong></li><li>Requests without valid tokens will be rejected</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MaDjlxde9aowhivHmL2D1Q.png" /></figure><p><strong>App Check Token Expiry:</strong></p><p>Once Firebase App Check has verified that your app is genuine, it provides your app with a temporary token. This token acts like a short-lived pass, proving to Firebase that your app is trusted while it communicates with the backend. Because these tokens are temporary, they eventually expire, but the good news is that the Firebase SDK takes care of refreshing them automatically. Your app can continue to interact with Firebase services without interruption, and most of the time, you don’t even have to think about it.</p><p>In some cases, such as debugging or making custom backend calls, you might want to manually fetch a new token. This can be done using a simple call like firebaseAppCheck.getToken(forceRefresh: true). The forceRefreshparameter determines whether Firebase should return a cached token if one exists or fetch a brand-new token from the server. Setting it to true forces a fresh token, while false allows Firebase to return a valid cached token if available. This flexibility can be very useful when testing or handling special scenarios in your app.</p><pre>firebaseAppCheck.getToken(forceRefresh: true)<br>.addOnSuccessListener(token -&gt; {<br>    // Use token if needed<br>})<br>.addOnFailureListener(e -&gt; {<br>    // Handle error<br>})</pre><p><strong>Common Issues That Can Break the Firebase App Check:</strong></p><p>Even though Firebase App Check works quietly in the background to protect your app, sometimes things can go wrong. Knowing these common issues can help you fix problems quickly and keep your app secure:</p><ul><li><strong>App Check token not sent</strong> — Firebase didn’t receive the verification token from your app.</li><li><strong>App not installed from the Play Store — </strong>App Check expects the app to come from a trusted source like Google Play.</li><li><strong>App Check is not enabled in the Firebase Console — </strong>App Check must be turned on for your project to work.</li><li><strong>Play Integrity API is not properly configured — </strong>The system that checks your app’s authenticity isn’t set up correctly.</li></ul><p><strong>Using App Check During Development and Debugging:</strong></p><p>While Play Integrity is the provider used in production to ensure your app is genuine, development and debugging require a slightly different approach. During development, your app may not be installed from the Play Store, or you might be testing on devices that aren’t certified. In these cases, Firebase provides a Debug App Check Provider that allows you to test and develop your app without running into verification issues.</p><p>Using the debug provider is simple. You can set it up with theDebugAppCheckProviderFactory which gives your app a debug token. This token acts like a temporary pass for your app during development, letting you test App Check functionality without requiring Play Integrity. Once your app is ready for production, you can switch back to Play Integrity to ensure full security for your real users.</p><p>Add a dependency in your <strong>app-level</strong> build.gradle file:</p><pre>dependencies {<br>    implementation &quot;com.google.firebase:firebase-appcheck-debug:LATEST_VERSION_HERE&quot;<br>}</pre><p>In your MainActivity or Application Class:</p><pre>val firebaseAppCheck = FirebaseAppCheck.getInstance()<br>firebaseAppCheck.installAppCheckProviderFactory(<br>    DebugAppCheckProviderFactory.getInstance()<br>)</pre><p>Now launch the app and check Logcat to get the debug token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RGX2hElIvYIIpEymuxlEXg.png" /><figcaption>Logcat Screenshot — App Check Debug Token</figcaption></figure><p>Add a debug token to App Check on the Firebase console to avoid blocking your test builds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_fB-dICXnAemfgvWLK08gA.png" /><figcaption>App Check — Firebase Console</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pMZhw2EZjt2K8Sm6uwi4Tw.png" /><figcaption>Manage debug tokens</figcaption></figure><p><strong>App Check request metrics:</strong></p><ul><li>App Check metrics show how many requests are coming from valid vs invalid apps.</li><li>You can see trends like:</li><li>Spike in invalid requests → possible attack or misuse</li><li>Drop in valid requests → maybe legitimate users are facing issues</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ZPkyobtWtLExhL-SvTDow.png" /><figcaption>App Check request metrics</figcaption></figure><p><strong>Demo Use Case Of Firestore: App Check-in Action</strong></p><pre>// Add collection to Firestore<br>val db = FirebaseFirestore.getInstance()<br><br>val data = hashMapOf(<br>    &quot;text&quot; to &quot;Hi from Firestore App Check demo&quot;<br>)<br><br>db.collection(&quot;messages&quot;)<br>    .document(&quot;hello&quot;)<br>    .set(data)<br>    .addOnSuccessListener {<br>        Log.d(&quot;DEMO&quot;, &quot;Document written successfully&quot;)<br>    }<br>    .addOnFailureListener { e -&gt;<br>        Log.e(&quot;DEMO&quot;, &quot;Firestore write failed&quot;, e)<br>    }</pre><p>Scenario 1: Legit App</p><ul><li>Installed from the Play Store</li><li>Valid App Check token</li><li>Firestore access allowed</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O_DnI6Wt2IUqozlWdygguA.png" /></figure><p>Scenario 2: Tampered App</p><ul><li>Modified APK</li><li>Invalid token</li><li>Firestore access blocked</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*chjiTHyFc3Voegj31TRU2w.png" /><figcaption>Logcat Screenshot — Permission Denied From Firestore</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M0oUJFG7HHViy1Fnjn8eyg.png" /><figcaption>Invalid App Check token</figcaption></figure><h3>Conclusion:</h3><p>Firebase App Check is not only simple to set up but also extremely effective at protecting your app and backend. Without it, your Firebase services are exposed, leaving your data vulnerable to fake apps, automated scripts, and potential misuse that can increase your billing unexpectedly.</p><p>By adding just a few lines of code, you can secure your Firebase data, block unauthorized access, and prevent abuse, all without interrupting your users’ experience. App Check works quietly in the background, giving you peace of mind that only your real, trusted app can communicate with Firebase, keeping both your users and your backend safe.</p><p><strong>Official Documentation</strong><br>Firebase App Check: <a href="https://firebase.google.com/docs/app-check">https://firebase.google.com/docs/app-check</a></p><p><strong>Happy Learning!</strong></p><p>If this guide helped you, show some love with 👏 and share it with your friends. Let’s make learning Firebase fun and easy for everyone. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d35cf3e7eb9b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/simform-engineering/firebase-app-check-with-play-integrity-api-in-android-d35cf3e7eb9b">Firebase App Check with Play Integrity API in Android</a> was originally published in <a href="https://medium.com/simform-engineering">Simform Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing .so Libraries: Best Practices for Seamless Integration]]></title>
            <link>https://medium.com/simform-engineering/optimizing-so-libraries-best-practices-for-seamless-integration-1b739fa6a66e?source=rss-54a4ef9db22b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b739fa6a66e</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[shared-libraries]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[tips-and-tricks]]></category>
            <dc:creator><![CDATA[Payal Rajput]]></dc:creator>
            <pubDate>Fri, 19 May 2023 14:09:18 GMT</pubDate>
            <atom:updated>2023-05-22T07:47:46.316Z</atom:updated>
            <content:encoded><![CDATA[<h3>Managing .so Libraries: Best Practices for Seamless Integration</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fzrGsU9WLxMExKxgcVhRew.png" /></figure><p>Shared libraries play a crucial role in the functioning of multiple applications. They streamline efficiency by <strong>eliminating duplicate library files</strong> and provide a native path for Java Native Interface (JNI) libraries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*ggrIhq5aTzMbhHJtUSCPDQ.png" /></figure><p>When it comes to<strong> managing .so libraries</strong>, it becomes paramount to ensure a seamless integration that enables your application to function flawlessly in real-time scenarios.</p><p>In this blog, we will explore invaluable tips and guidelines for effectively managing .so libraries and insights into addressing potential issues that may arise during the Play Store publishing process.</p><h4><strong>Choosing the Right .so Libraries</strong></h4><p>Determining the appropriate .so libraries to include in your application is vital. These libraries contain native code that enables specific functions within your app. To make informed decisions, it is essential to consult the documentation of any third-party libraries you utilize and verify their compatibility with your target platforms.</p><p>Here are some popular libraries widely used in app development:<br><strong>1) SQLite:</strong> A powerful library renowned for efficient database management in apps.<br><strong>2) OpenAL:</strong> An audio processing library that finds utility in numerous games and other apps. <br><strong>3) Glide Transformations:</strong> An Android transformation library providing a variety of image transformations for seamless integration with <a href="https://github.com/bumptech/glide">Glide</a>.</p><p>To ensure proper integration, make sure to include .so library files in your project’s <strong>/src/main/jniLibs/</strong> directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*mYJVeo0ChV1E8u-4OLRdaw.jpeg" /></figure><h3><strong>Verifying Library Compatibility and Packaging</strong></h3><p>To avoid compatibility issues and ensure optimal performance,</p><ul><li>Ensure that in your project’s <strong>build.gradle </strong>file, the Android Gradle plugin is set to “ndk”; specify the different CPU architectures your app will support, such as ARM, ARM64, x86, and x86_64.</li><li>Use the<strong> ‘file’</strong> command in the terminal to check the architecture of your .so files. For example, if you have a file called libexample.so, you can run ‘<strong>file libexample.so’</strong> in the terminal to see the architecture.</li><li>Inspect the APK file generated by your build process to ensure the .so libraries are packaged with your app.</li><li>Make sure to use the latest version of the .so libraries to avoid compatibility issues. Regularly check for updates and replace the outdated .so libraries with new ones.</li><li>Before publishing your app on the Play Store, perform rigorous testing to identify and resolve any issues related to .so library integration.</li><li>Fine-tune your app’s performance by utilizing 32-bit and 64-bit libraries to ensure it runs smoothly on different devices.</li></ul><h3><strong>Supporting 32-bit and 64-bit Architectures</strong></h3><p>If you have developed your app solely in Java or Kotlin, you don’t need to worry about the device used for downloading. But, if you’ve added native code, ensure it can work on both 32-bit and 64-bit devices.</p><ul><li>To check for 64-bit libraries, examine the structure of your APK file. The APK includes necessary native libraries in various folders based on the ABI (Application Binary Interface). While you don’t need to support every 64-bit architecture, you must include the corresponding 64-bit architecture for each native 32-bit architecture you support.</li><li><strong>For the ARM architecture,</strong> the 32-bit libraries are located in <strong>armeabi-v7a </strong>folder. The 64-bit equivalent is placed in <strong>arm64-v8a </strong>folder.</li><li><strong>For the x86 architecture,</strong> 32-bit libraries reside in <strong>x86</strong> and 64-bit in <strong>x86_64 </strong>folder.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3M18vCfH3jbdKdB6d3X8EQ.png" /></figure><blockquote><strong>Note:</strong> Ensure that you have native libraries in both 32-bit and 64-bit architecture folders. For more detailed information, refer to the document provided <a href="https://developer.android.com/google/play/requirements/64-bit">here</a>.</blockquote><h3><strong>Building 64-bit Libraries</strong></h3><p>To build 64-bit libraries, follow these instructions:</p><h4><strong>Configure Android Studio and Gradle</strong></h4><p>Android Studio, a powerful software for Android development, utilizes Gradle as its build tool. To ensure compatibility with different devices, make some modifications to your app’s ‘<strong>build.gradle</strong>’ file. This code specifies the types of devices your app should work on. Simply add “arm64-v8a” and/or “x86_64” to the file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t3Cpg7zyMSafIoKKjEc_iA.png" /></figure><p>The ‘<strong>ndk.abiFilters</strong>’ controls the ABIs (Application Binary Interfaces) the Android Gradle plugin should build and package native libraries for. When the flag is not configured, Gradle builds and packages all available ABIs.</p><blockquote>For more detailed instructions, refer to the documentation provided <a href="https://developer.android.com/google/play/requirements/64-bit#build-with-64-bit">here</a>.</blockquote><h4><strong>Resolving Play Store Publish Issues</strong></h4><p>To tackle real-time scenarios like play store issues, here are the steps you can follow:</p><ul><li>Check the Google Play Console for any error messages or warnings that may prevent your app&#39;s publication. Resolve any identified issues. For example:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*Q2XIHtA68RT0sZbCFtoAzQ.png" /></figure><ul><li>Ensure that your app complies with the Google Play Developer Program Policies. If your app violates any of the policies, it will not be allowed to be published on the Play Store.</li><li>If your app is rejected due to issues with .so libraries, verify that they are correctly included and compatible with the architectures specified in your app’s <strong>build.gradle</strong> file.</li><li>Ensure that your app includes all the necessary libraries for the target devices. Use the “Supported devices” feature in the Play Console to specify the supported devices and required architectures.</li><li>If you are unable to fix the issue, reach out to Google Play Support for assistance. They can provide detailed guidance on resolving the issue and help you successfully publish your app on the Play Store.</li></ul><p>By following these tips and guidelines, you can manage .so libraries and ensure your application works perfectly fine in real-time scenarios. Remember to prioritize testing and performance optimization, using native libraries only when necessary and regularly updating outdated versions.</p><p>If you’re eager to dive deeper into generating 32-bit and 64-bit libs, let us know!</p><blockquote><em>Stay connected with </em><a href="https://medium.com/simform-engineering"><strong><em>Simform Engineering</em></strong></a><em> for more exciting and informative content.</em></blockquote><blockquote><em>Thank you for reading. Happy coding :)</em></blockquote><blockquote><em>Follow us: </em><a href="https://twitter.com/simform"><strong><em>Twitter</em></strong></a><strong><em> | </em></strong><a href="https://www.linkedin.com/company/simform/"><strong><em>LinkedIn</em></strong></a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b739fa6a66e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/simform-engineering/optimizing-so-libraries-best-practices-for-seamless-integration-1b739fa6a66e">Optimizing .so Libraries: Best Practices for Seamless Integration</a> was originally published in <a href="https://medium.com/simform-engineering">Simform Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[List view with Pagination using Jetpack Compose]]></title>
            <link>https://medium.com/simform-engineering/list-view-with-pagination-using-jetpack-compose-e131174eac8e?source=rss-54a4ef9db22b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e131174eac8e</guid>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[pagination]]></category>
            <category><![CDATA[lists]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Payal Rajput]]></dc:creator>
            <pubDate>Tue, 10 Aug 2021 12:37:47 GMT</pubDate>
            <atom:updated>2021-08-10T12:37:47.969Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4df9b2XNkpmvYl-p4_2oSA.png" /></figure><h3><strong>Introduction: -</strong></h3><p><strong>Jetpack Compose</strong> is <strong>Android’s</strong> modern toolkit for building native UI using composable functions. It simplifies and accelerates UI development on <strong>Android</strong>. Quickly bring your app to life with less code, powerful tools, and intuitive Kotlin APIs. Composable functions increase code reusability.</p><p>Benefits Of Jetpack Compose:-</p><ol><li>It’s fully written in Kotlin.</li><li>User interfaces are broken up into small components called composable functions.</li><li>Supports Material Design theming and components and animations from the start, allowing developers to focus on creating beautiful user interfaces that much quicker.</li><li>You own the state. So just simply pass the state into the composable so that it can observe the state and update itself accordingly.</li></ol><p>In this blog, we will learn:</p><ul><li>Building <strong>Lists</strong> with Jetpack compose</li><li><strong>API Call</strong> using Retrofit</li><li>Jetpack compose <strong>Paging Library 3.0</strong></li></ul><p>It is very easy to create a list(with paging) in Jetpack compose, and even without handling any adapter for the item list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*1-aSwTPt2S-vaMAJDXaEJw.gif" /></figure><h3>Let’s begin!</h3><ul><li>You need the latest android studio canary version. You can download it from <a href="https://developer.android.com/studio/preview">here</a></li><li>If you are new to Jetpack Compose I would recommend going through the official <a href="https://developer.android.com/jetpack/compose">documentation</a> first.</li></ul><h3>Dependency Setup:-</h3><pre>//Retrofit<br>implementation &#39;com.squareup.retrofit2:retrofit:2.9.0&#39;<br>implementation &#39;com.squareup.retrofit2:converter-gson:2.9.0&#39;<br><br>//okHttp<br>implementation &#39;com.squareup.okhttp3:okhttp:4.9.0&#39;<br>implementation &#39;com.squareup.okhttp3:logging-interceptor:4.9.0&#39;<br><br>//Coil (Image Uploading)<br>implementation &#39;com.google.accompanist:accompanist-coil:0.12.0&#39;<br><br>//Paging 3.0<br>implementation &#39;androidx.paging:paging-compose:1.0.0-alpha10&#39;</pre><h3>Manifest:-</h3><p>Add Internet permission in your manifest file.</p><pre>&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;</pre><h3>Code Setup:-</h3><p><strong>Listview</strong></p><p>The equivalent component to ListView in Jetpack Compose is <a href="https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/package-summary#lazycolumn">LazyColumn</a> for a vertical list and <a href="https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/package-summary#lazyrow">LazyRow</a> for a horizontal list. Compose provides a set of components which only compose and lay out items which are visible in the component’s viewport.</p><p>You can use it by formatting your data as a list and passing it with a @Composable callback that emits the UI for a given item in the list.</p><pre>@Composable<br>fun EmployeeItem(empData: User, onClick: () -&gt; Unit) {<br>    <em>Card</em>(<br>        modifier = Modifier<br>            .<em>padding</em>(bottom = 5.<em>dp</em>, top = 5.<em>dp</em>,<br>                start = 5.<em>dp</em>, end = 5.<em>dp</em>)<br>            .<em>fillMaxWidth</em>()<br>            .<em>clickable</em>(onClick = onClick),<br>        shape = <em>RoundedCornerShape</em>(15.<em>dp</em>),<br>        elevation = 12.<em>dp<br>    </em>) <strong>{<br>        </strong><em>Row</em>(<br>            modifier = Modifier<br>                .<em>clip</em>(<em>RoundedCornerShape</em>(4.<em>dp</em>))<br>                .<em>background</em>(MaterialTheme.colors.surface)<br>        ) <strong>{<br>            </strong><em>Surface</em>(<br>                modifier = Modifier.<em>size</em>(130.<em>dp</em>),<br>                shape = <em>RoundedCornerShape</em>(12.<em>dp</em>),<br>                color = MaterialTheme.colors.surface.copy(<br>                            alpha = 0.2f)<br>            ) <strong>{<br>                </strong>val image = <em>rememberCoilPainter</em>(<br>                                request = empData.avatar, <br>                                fadeIn = true)<br>                <em>Image</em>(<br>                    painter = image,<br>                    contentDescription = null,<br>                    modifier = Modifier<br>                        .<em>height</em>(100.<em>dp</em>)<br>                        .<em>clip</em>(shape = <em>RoundedCornerShape</em>(12.<em>dp</em>)),<br>                    contentScale = ContentScale.Crop<br>                )<br>            <strong>}<br>            </strong><em>Column</em>(<br>                modifier = Modifier<br>                    .<em>padding</em>(start = 12.<em>dp</em>)<br>                    .<em>align</em>(Alignment.CenterVertically)<br>            ) <strong>{<br>                </strong><em>Text</em>(<br>                    text = empData.first_name,<br>                    fontWeight = FontWeight.Bold,<br>                    style = TextStyle(fontSize = 22.<em>sp</em>), <br>                    color = Color.Black<br>                )<br>                <em>CompositionLocalProvider</em>(<br>                    <em>LocalContentAlpha </em>provides ContentAlpha.medium<br>                ) <strong>{<br>                    </strong><em>Text</em>(<br>                        text = empData.email,<br>                        style = <em>typography</em>.body2,<br>                        maxLines = 1, <br>                        overflow = TextOverflow.Ellipsis,<br>                        modifier = Modifier.<em>padding</em>(end = 25.<em>dp</em>)<br>                    )<br>                <strong>}<br>            }<br>        }<br>    }<br></strong>}</pre><p>We need to pass two arguments in <strong>EmployeeItem</strong> composable function: <br>empData : User data for list item.<br>onClick : Lambda function to execute when the list item is clicked.</p><p><strong>API Call Using Retrofit</strong></p><p>Now we have to create a data class to define how our data from the network<br>will look like and hold it temporarily.</p><pre>data class UserResponse (<br>    var page: Int,<br>    var per_page: Int,<br>    var total: Int,<br>    var total_pages: Int,<br>    var data: List&lt;User&gt;,<br>    var support: Support<br>)<br><br>data class User(<br>    var id: Int,<br>    var email: String,<br>    var first_name: String,<br>    var last_name: String,<br>    var avatar: String<br>)<br><br>data class Support(<br>    var url: String,<br>    var text: String<br>)</pre><p>Now create an interface to define the endpoint of our api. The interface contains a method which when called will run the API using specified endpoints.</p><pre>interface RetrofitService {<br>    @GET(&quot;users&quot;)<br>    suspend fun getUserList(@Query(&quot;page&quot;) page: Int) : UserResponse<br>}</pre><p>This API call is of type GET . This will return a call object containing data which is in the form of UserResponse data class.</p><p>Next, we create a RetrofitClient class to call API using a retrofit.</p><pre>object RetrofitClient {<br>    private fun getClient(): Retrofit {<br>        return Retrofit.Builder()<br>            .baseUrl(&quot;https://reqres.in/api/&quot;)<br>            .client(getOkHttpClient())<br>            .addConverterFactory(GsonConverterFactory.create())<br>            .build()<br>    }<br>    <br>    val apiService: RetrofitService =                        getClient().create(RetrofitService::class.<em>java</em>)<br><br>    private fun getLoggingIntercepter() =<br>HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.<em>BASIC</em>)</pre><pre>    private fun getOkHttpClient() = OkHttpClient.Builder().addInterceptor(getLoggingIntercepter()).build()<br>}</pre><p>We have used OKhttp client for retrofit to make a call. Next, we create a retrofit builder object that will contain the base URL of the API, the <em>Gson Converter</em> is used to convert our Json API response. Then we declared apiService variable that will be used to connect the retrofit builder object with our interface and make one complete retrofit call.</p><p>Now we are going to use this RetrofitClient object to set and bind response data with our item list using pagination.</p><p><strong>Pagination using Jetpack paging 3.0</strong></p><p>When exposing large data sets through APIs, it needs to provide a mechanism to paginate the list of resources.</p><p>First of all, you need to implement the <strong>PagingSource</strong>. To implement that you need to pass the type of the paging key and type of data to load.</p><pre>class UserSource : PagingSource&lt;Int, User&gt;() {<br>    <br>    override fun getRefreshKey(state: PagingState&lt;Int, User&gt;): Int?<br>{<br>        return state.anchorPosition<br>    }<br><br>    override suspend fun load(params: LoadParams&lt;Int&gt;):            LoadResult&lt;Int, User&gt; {<br>        return try {<br>            val nextPage = params.key ?: 1<br>            val userList = RetrofitClient.apiService.getUserList(page = nextPage)<br>            LoadResult.Page(<br>                data = userList.data,<br>                prevKey = if (nextPage == 1) null else nextPage - 1,<br>                nextKey = if (userList.data.isEmpty()) null else userList.page + 1<br>            )<br>        } catch (exception: IOException) {<br>            return LoadResult.Error(exception)<br>        } catch (exception: HttpException) {<br>            return LoadResult.Error(exception)<br>        }<br>    }<br>}</pre><p>After implementing PagingSource we have to create <strong>Pager</strong> in ViewModel and also have to specify the page size.</p><pre>class EmployeeViewModel : ViewModel() {<br>    val user: Flow&lt;PagingData&lt;User&gt;&gt; = Pager(PagingConfig(pageSize = 6)) <strong>{<br>        </strong>UserSource()<br>    <strong>}</strong>.flow.<em>cachedIn</em>(<em>viewModelScope</em>)<br>}</pre><p>In Paging 3.0 we don’t need to handle or convert any data to survives the screen configuration changes. You can simply cache the API result. Using <strong><em>cachedIn</em>(<em>viewModelScope</em>) </strong>we can cache the paging data into viewModel.</p><p>To notify change of paging data you can handle loading state as below using <strong>CombinedLoadState </strong>callback:</p><pre>@Composable<br>fun UserList(modifier: Modifier = Modifier, viewModel:               EmployeeViewModel, context: Context) {<br>    <em>UserInfoList</em>(modifier, userList = viewModel.user, context)<br>}<br><br>@Composable<br>fun UserInfoList(modifier: Modifier, userList: Flow&lt;PagingData&lt;User&gt;&gt;, context: Context) {<br>    val userListItems: LazyPagingItems&lt;User&gt; =            userList.<em>collectAsLazyPagingItems</em>()<br><br>    <em>LazyColumn </em><strong>{<br>        </strong><em>items</em>(userListItems) <strong>{ </strong>item <strong>-&gt;<br>            </strong>item?.<em>let </em><strong>{<br>                </strong><em>EmployeeItem</em>(empData = <strong>it</strong>, onClick = <strong>{<br>                    </strong>Toast.makeText(context, item.id.toString(),   Toast.<em>LENGTH_SHORT</em>).show()<br>                <strong>}</strong>)<br>            <strong>}<br>        }<br>        </strong>userListItems.<em>apply </em><strong>{<br>            </strong>when {<br>                loadState.refresh is LoadState.Loading -&gt; {<br>                    //You can add modifier to manage load state when first time response page is loading<strong><br>                </strong>}<br>                loadState.append is LoadState.Loading -&gt; {<br>                    //You can add modifier to manage load state when next response page is loading<strong><br>                </strong>}<br>                loadState.append is LoadState.Error -&gt; {<br>                    //You can use modifier to show error message <strong><br>                </strong>}<br>            }<br>        <strong>}<br>    }<br></strong>}</pre><p>Now to represent data to UI layer, you just have to call above UserList composable function from your Jetpack MainActivity’s setContent, pass viewModel and context in the parameter as below:</p><pre>class MainActivity : ComponentActivity() {<br><br>    private val employeeViewModel: EmployeeViewModel by <em>viewModels</em>()<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        <em>setContent </em><strong>{<br>            </strong><em>ListWithAPIAndPaginationTheme </em><strong>{<br>                </strong><em>UserList</em>(viewModel = employeeViewModel, context = this)<br>            <strong>}<br>        }<br>    </strong>}<br>}</pre><p>So yeah that’s it….you’re done with your listing with API call and pagination using Jetpack compose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*6-LJN89YvmiMs_RT48LHJQ.gif" /></figure><h4>That’s it if you run this setup now it will produce the following output.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*PsEkd-BwHd-v0J6s7UNOqQ.gif" /></figure><h3><strong>Conclusion:-</strong></h3><p>In this blog, we have learned list view in Jetpack Compose. To show a list of elements using the legacy way is by using Recyclerview. It’s a little complicated, tedious to implement and it’s the exact opposite of the Jetpack Compose and the declarative approach. After all, we only want to create a list with some elements inside.</p><p>With the current approach of pagination, you have to put a new element into your data set and force the RecyclerView to render it as a progress bar. With Compose, implementing pagination is really simple — it only takes a few lines of code!</p><p><strong>Happy Learning :)</strong></p><p>If you found this article helpful then please give multiple 👏 and also share with your friends. Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e131174eac8e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/simform-engineering/list-view-with-pagination-using-jetpack-compose-e131174eac8e">List view with Pagination using Jetpack Compose</a> was originally published in <a href="https://medium.com/simform-engineering">Simform Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>