Google se compromete a impulsar la igualdad racial para las comunidades afrodescendientes. Obtén información al respecto.

PagingConfig

class PagingConfig
kotlin.Any
   ↳ androidx.paging.PagingConfig

An object used to configure loading behavior within a Pager, as it loads content from a PagingSource.

Summary

Constants
const Int

When maxSize is set to MAX_SIZE_UNBOUNDED, the maximum number of items loaded is unbounded, and pages will never be dropped.

Public constructors
<init>(pageSize: Int, @IntRange(0) prefetchDistance: Int = pageSize, enablePlaceholders: Boolean = true, @IntRange(1) initialLoadSize: Int = pageSize * DEFAULT_INITIAL_PAGE_MULTIPLIER, @IntRange(2) maxSize: Int = MAX_SIZE_UNBOUNDED, jumpThreshold: Int = COUNT_UNDEFINED)

An object used to configure loading behavior within a Pager, as it loads content from a PagingSource.

Properties
Boolean

Defines whether PagingData may display null placeholders, if the PagingSource provides them.

Int

Defines requested load size for initial load from PagingSource, typically larger than pageSize, so on first load data there's a large enough range of content loaded to cover small scrolls.

Int

Threshold for number of items scrolled outside the bounds of loaded items to trigger invalidate.

Int

Defines the maximum number of items that may be loaded into PagingData before pages should be dropped.

Int

Defines the number of items loaded at once from the PagingSource.

Int

Prefetch distance which defines how far from the edge of loaded content an access must be to trigger further loading.

Constants

MAX_SIZE_UNBOUNDED

const val MAX_SIZE_UNBOUNDED: Int

When maxSize is set to MAX_SIZE_UNBOUNDED, the maximum number of items loaded is unbounded, and pages will never be dropped.

Value: Int.MAX_VALUE

Public constructors

<init>

PagingConfig(
    pageSize: Int,
    @IntRange(0) prefetchDistance: Int = pageSize,
    enablePlaceholders: Boolean = true,
    @IntRange(1) initialLoadSize: Int = pageSize * DEFAULT_INITIAL_PAGE_MULTIPLIER,
    @IntRange(2) maxSize: Int = MAX_SIZE_UNBOUNDED,
    jumpThreshold: Int = COUNT_UNDEFINED)

An object used to configure loading behavior within a Pager, as it loads content from a PagingSource.

Properties

enablePlaceholders

val enablePlaceholders: Boolean

Defines whether PagingData may display null placeholders, if the PagingSource provides them.

PagingData will present null placeholders for not-yet-loaded content if two conditions are met:

  1. Its PagingSource can count all unloaded items (so that the number of nulls to present is known).
  2. enablePlaceholders is set to true

initialLoadSize

val initialLoadSize: Int

Defines requested load size for initial load from PagingSource, typically larger than pageSize, so on first load data there's a large enough range of content loaded to cover small scrolls.

jumpThreshold

val jumpThreshold: Int

Threshold for number of items scrolled outside the bounds of loaded items to trigger invalidate. Defaults to COUNT_UNDEFINED, which disables invalidation due to scrolling large distances.

maxSize

val maxSize: Int

Defines the maximum number of items that may be loaded into PagingData before pages should be dropped.

If set to MAX_SIZE_UNBOUNDED, pages will never be dropped.

This can be used to cap the number of items kept in memory by dropping pages. This value is typically many pages so old pages are cached in case the user scrolls back.

This value must be at least two times the prefetchDistance plus the pageSize). This constraint prevent loads from being continuously fetched and discarded due to prefetching.

maxSize is best effort, not a guarantee. In practice, if maxSize is many times pageSize, the number of items held by PagingData will not grow above this number. Exceptions are made as necessary to guarantee:

  • Pages are never dropped until there are more than two pages loaded. Note that a PagingSource may not be held strictly to requested pageSize, so two pages may be larger than expected.
  • Pages are never dropped if they are within a prefetch window (defined to be pageSize + (2 * prefetchDistance)) of the most recent load.

pageSize

val pageSize: Int

Defines the number of items loaded at once from the PagingSource.

Should be several times the number of visible items onscreen.

Configuring your page size depends on how your data is being loaded and used. Smaller page sizes improve memory usage, latency, and avoid GC churn. Larger pages generally improve loading throughput, to a point (avoid loading more than 2MB from SQLite at once, since it incurs extra cost).

If you're loading data for very large, social-media style cards that take up most of a screen, and your database isn't a bottleneck, 10-20 may make sense. If you're displaying dozens of items in a tiled grid, which can present items during a scroll much more quickly, consider closer to 100.

prefetchDistance

val prefetchDistance: Int

Prefetch distance which defines how far from the edge of loaded content an access must be to trigger further loading. Typically should be set several times the number of visible items onscreen.

E.g., If this value is set to 50, a PagingData will attempt to load 50 items in advance of data that's already been accessed.

A value of 0 indicates that no list items will be loaded until they are specifically requested. This is generally not recommended, so that users don't observe a placeholder item (with placeholders) or end of list (without) while scrolling.