Infinite Scrolling With Android Paging Library and Flow API

Infinite Scrolling With Android Paging Library and Flow API

I was given an API that supports paging and off I went coding away. There was just one problem. I had never implemented this behaviour before, therefore, I was able to code an app that fetches results from the API, but I failed to implement the endless scrolling feature in the allowed time frame.

Recently I was interviewed for and android software development position, and i was asked to live code a simple app that demonstrates fetching a list of items from a network resource, and display their information in an endless list.

I was given an API that supports paging and off I went coding away.

There was just one problem.

I had never implemented this behaviour before, therefore, I was able to code an app that fetches results from the API, but I failed to implement the endless scrolling feature in the allowed time frame.

So, this means I now have a great topic for a blogpost!.

What is endless scrolling?

You know when you scroll through Facebook or Instagram, and it seems as though the list of posts is so big you might never get to the end of it? Well, that’s because it’s true.

But loading huge amounts of data and feeding it to our recycler view would definitely be a problem.

It would clog the apps memory, or local storage, and will no doubt be detrimental for performance.

How can we make it better?

We can load a chunk of the data, then, when we have finished scrolling through it, we can load another chunk, right? Sounds good.

We would have to manage this though, make sure we don’t keep useless data, but also keep loaded data for reverse scrolling, we would also need to manage all those API calls and cancel them if needed, apply multithreading logic and keep the aliens from reaching the kill switch on Alpha centaury…

Well, apart from that last thing about the aliens, there is a simple solution to manage all those issues

pagination paging kotlin paging-library android

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Top Android Projects with Source Code

Android projects with source code - Work on real-time android projects. We’ll start project ideas from beginners level and later move to advance projects.

Kotlin Coroutines on Android - How to use Coroutines on Android

Coroutines are a Kotlin feature that convert async callbacks for long-running tasks, such as database or network access, into sequential code. This Kotlin Coroutines tutorial will show you how to use coroutines on Android, and how the new androidx-concurrent library makes it easy to use them to get things off the main thread. You'll also learn how the new library helps coroutines work with Architecture Components. This session also covers coroutine patterns, best practices, and even how to test coroutines!

Building Dark Mode Theme in Android

Hello World, today we are going to see how we can implement a dark theme or night mode in our android application. This tutorial is going to be very simple and easy to understand. The dark theme is attractive to users and it is comfortable for low light conditions.

Kotlin vs Flutter | Flutter vs Kotlin Performance

It is a thing of the past when cross-platform applications could only be developed using React Native. This happened because the developers and the ones involved in business have started examining more routes through mobile app development for reaching a broader audience across the entire globe.

Build A Simple Application For Android Using Kotlin And Android Studio

Build A Simple Application For Android Using Kotlin And Android Studio - We will create a simple calculator android application which would be able to perform simple arithmetic calculations like…