Search code examples
androidandroid-architecture-components

Why do I need to use the new Paging library? (Android Architecture Components)


I am really interested in newly introduced Android Architecture Components. But I can't say that I understand what is the 'Paging' library about.

It looks like it's purpose is to provide help with data pagination. But isn't that already an easy thing? Like I can just hold some integer values somewhere in my code and then use them later in my network / room database query.

It's clear that I am missing something here. Please help me understand the need of Paging library


Solution

  • The paging library is indeed for use with data pagination for a data source, this data source can be as simple as a single table in a database or as complex as multiple tables and multiple network api sources as set out in your own custom data source class.

    The pagination library not only provides smooth pagination from your data source, but it also provides seamless background updates to the individual recycler view items already shown. I personally hate calling notifyDataSetChanged when unsure of how many items are being changed, and I look forward to the opportunity to have the currently shown list diffed against the requested list form a background thread, with items individually inserted, removed, and updated where necessary.

    The full architecture from the pagedListAdapter to the datasource, perfectly separates each concern (making testing easier), and if followed provides a way for a commonly used (and often poorly implemented) aspect of android to be implemented well. This improves individual software quality, user and developer experience (It's fairly simple), and enhances the android brand as a whole (by improving android software quality as a whole).