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

Infinite Scrolling With Android Paging Library and Flow API
9.55 GEEK