# PagingConfig

Artifact: [androidx.paging:paging-common](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingConfig.kt+class:androidx.paging.PagingConfig) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  class PagingConfig
  ```

*** ** * ** ***

An object used to configure loading behavior within a `https://developer.android.com/reference/kotlin/androidx/paging/Pager`, as it loads content from a `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource`.

## Summary

| ### Constants |
|---|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#MAX_SIZE_UNBOUNDED()` When `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#maxSize()` is set to `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#MAX_SIZE_UNBOUNDED()`, the maximum number of items loaded is unbounded, and pages will never be dropped. | Cmn |

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#PagingConfig(kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int)( pageSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, prefetchDistance: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, enablePlaceholders: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, initialLoadSize: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, maxSize: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 2) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, jumpThreshold: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#enablePlaceholders()` Defines whether `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` may display `null` placeholders, if the `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource` provides them. | Cmn |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 1) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#initialLoadSize()` Defines requested load size for initial load from `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource`, typically larger than `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#(kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int)`, so on first load data there's a large enough range of content loaded to cover small scrolls. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#jumpThreshold()` Defines a threshold for the number of items scrolled outside the bounds of loaded items before Paging should give up on loading pages incrementally, and instead jump to the user's position by triggering REFRESH via invalidate. | Cmn |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 2) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#maxSize()` Defines the maximum number of items that may be loaded into `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` before pages should be dropped. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#pageSize()` Defines the number of items loaded at once from the `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource`. | Cmn |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#prefetchDistance()` Prefetch distance which defines how far from the edge of loaded content an access must be to trigger further loading. | Cmn |

## Constants

### MAX_SIZE_UNBOUNDED

Cmn

```
const val MAX_SIZE_UNBOUNDED: Int
```

When `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#maxSize()` is set to `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#MAX_SIZE_UNBOUNDED()`, the maximum number of items loaded is unbounded, and pages will never be dropped.

## Public constructors

### PagingConfig

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

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

## Public properties

### enablePlaceholders

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
val enablePlaceholders: Boolean
```

Defines whether `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` may display `null` placeholders, if the `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource` provides them.

`https://developer.android.com/reference/kotlin/androidx/paging/PagingData` will present `null` placeholders for not-yet-loaded content if two conditions are met:

1. Its `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource` can count all unloaded items (so that the number of nulls to present is known).

2. `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#(kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int)` is set to `true`

### initialLoadSize

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
val initialLoadSize: @IntRange(from = 1) Int
```

Defines requested load size for initial load from `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource`, typically larger than `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#(kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int)`, so on first load data there's a large enough range of content loaded to cover small scrolls.

Note: `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#(kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int)` is used to inform `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadParams#loadSize()`, but is not enforced. A `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource` may completely ignore this value and still return a valid initial `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page`.

### jumpThreshold

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
val jumpThreshold: Int
```

Defines a threshold for the number of items scrolled outside the bounds of loaded items before Paging should give up on loading pages incrementally, and instead jump to the user's position by triggering REFRESH via invalidate.

Defaults to `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page#COUNT_UNDEFINED()`, which disables invalidation due to scrolling large distances.

Note: In order to allow `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource` to resume from the user's current scroll position after invalidation, `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#getRefreshKey(androidx.paging.PagingState)` must be implemented.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#getRefreshKey(androidx.paging.PagingState)` |   |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#jumpingSupported()` |   |

### maxSize

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
val maxSize: @IntRange(from = 2) Int
```

Defines the maximum number of items that may be loaded into `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` before pages should be dropped.

If set to `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#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 `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#(kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int)` plus the `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#(kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int)`). This constraint prevent loads from being continuously fetched and discarded due to prefetching.

`https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#(kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int)` is best effort, not a guarantee. In practice, if `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#(kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int)` is many times `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#(kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int)`, the number of items held by `https://developer.android.com/reference/kotlin/androidx/paging/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 `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource` may not be held strictly to `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#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.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#MAX_SIZE_UNBOUNDED()` |   |

### pageSize

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
val pageSize: Int
```

Defines the number of items loaded at once from the `https://developer.android.com/reference/kotlin/androidx/paging/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.

Note: `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#(kotlin.Int,kotlin.Int,kotlin.Boolean,kotlin.Int,kotlin.Int,kotlin.Int)` is used to inform `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadParams#loadSize()`, but is not enforced. A `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource` may completely ignore this value and still return a valid `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page`.

### prefetchDistance

Cmn Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
val prefetchDistance: @IntRange(from = 0) 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 `https://developer.android.com/reference/kotlin/androidx/paging/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.