This post is a basic set up for using Paging3 to page though data progressively when requesting a large dataset.
It relies on coroutines and Flow for handling concurrency, but Paging3 also has support for using RxJava, or a ListenableFuture from Guava.
I am also showing an example using jetpack Compose, but support for using a View-based RecyclerView (based on a PagingDataAdapter).
Dependency Injection is mentioned but is not impactful on the subject.
Stack info
Here is the list of tech choices made for this implementation example
Paging3
Kotlin
gradle build file
Dependency Injection with Hilt
Jetpack Compose
Flow
Coroutines
Repository and DAO
LazyColumn
Using Paging3 to page a data request Cheat sheet
Dependencies
implementation("androidx.paging:paging-runtime:$paging_version") // versions are currently not aligned for paging-compose implementation("androidx.paging:paging-compose:3.3.2")
// needed for cachedIn() operator implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
DAO interface
@Query(« Select * from mydata ») fun loadAllPaged() : PagingSource<Int, MyDataEntity>
Repository class
// inject myDao with DI
fun loadAllMyDataEntityPaged() : PagingSource<Int, MyDataEntity> = myDao.loadAllPaged()
Nous utilisons des cookies sur notre site pour faire des statistiques de visites. En cliquant sur “Accepter tous”, vous autorisez l'utilisation de tous nos cookies. Vous pouvez régler plus finement l'utilisation de cookies en utilisant le lien "Cookie Settings".
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Durée
Description
cookielawinfo-checkbox-advertisement
1 year
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Advertisement".
cookielawinfo-checkbox-analytics
1 year
This cookies is set by GDPR Cookie Consent WordPress Plugin. The cookie is used to remember the user consent for the cookies under the category "Analytics".
cookielawinfo-checkbox-necessary
1 year
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
1 year
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Others".
cookielawinfo-checkbox-performance
1 year
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Cookie
Durée
Description
_ga
2 years
This cookie is installed by Google Analytics. The cookie is used to calculate visitor, session, campaign data and keep track of site usage for the site's analytics report. The cookies store information anonymously and assign a randomly generated number to identify unique visitors.
_gat_gtag_UA_201428095_1
1 minute
This cookie is set by Google and is used to distinguish users.
_gid
1 day
This cookie is installed by Google Analytics. The cookie is used to store information of how visitors use a website and helps in creating an analytics report of how the website is doing. The data collected including the number visitors, the source where they have come from, and the pages visted in an anonymous form.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.