Google has released a new version of the Paging API. The company says Paging API 3 is a complete overhaul of the library based on Kotlin. The idea was to incorporate the changes asked for by developers, which include simpler handling of errors, wider list transformations, and support for list, footer, and header separators. The alpha API still supports Java users. Here’s what you need to know.
The Paging 3 API covers a wide range of functions. At its core, it lets developers load in large sets of data over time in such a way as to reduce network use and cut down on system resource drain. It automates certain tasks that developers would otherwise have to undertake themselves.
Some of the functionalities include the ability to keep track of the keys used for retrieving the next and previous page, as well as automatically requesting the correct page when users scroll down through loaded data. The API ensures that users can’t trigger multiple requests at the same time and tracks the loading state so it can be displayed in the right spot of the user interface. Easy retry functions are offered, and the API allows for common operations, such as map or filters to be displayed, whether the developer is using Flow, RxJava, or others. It provides for simple list separator implementation, and, last, reduces data caching to a simple task. Google says some of these are backward compatible with Paging API 2.0, though it didn’t specify which ones.
Google insists that adopting the API within an app is a straight-forward process. For example, the Paging library talks directly to the recommended Android app architecture in every single layer of the app. Depending on where you’re drawing the data from, developers can implement a PagingSource or a PagingSource and RemoteMediator. Single data sources, such as a network or database, can get away with the PagingSource, while data that’s coming from layered sources, such as a network and a local database with also need the RemoteMediator to merge the sources. A PagingSource defines the source of the data and how to pull that data in and display it correctly. This is found in the repository layer
Google created the Paging 3 library to help developers handle simple and complex data pulls thanks to the way it manages information from multiple sources. The Paging 3 API is still in alpha, so as always Google is asking for help in ironing out the bugs. Documentation is available here.
Go to Source
Author: <a href="https://www.programmableweb.com/user/%5Buid%5D">EricZeman</a>