# PagingDataPresenter

# PagingDataPresenter

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/paging/PagingDataPresenter "View this page in Java")
Common/AllAndroid/JVMNative/C/iOSJavaScript
  - Cmn  

  ```
  abstract class PagingDataPresenter<T : Any>
  ```

*** ** * ** ***

The class that connects the UI layer to the underlying Paging operations. Takes input from UI presenters and outputs Paging events (Loads, LoadStateUpdate) in response.

Paging front ends that implement this class will be able to access loaded data, LoadStates, and callbacks from LoadState or Page updates. This class also exposes the[PagingDataEvent](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataEvent)from a[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData)for custom logic on how to present Loads, Drops, and other Paging events.

For implementation examples, refer to AsyncPagingDataDiffer for RecyclerView, or LazyPagingItems for Compose.

## Summary

|                                                                                                                                                                                                                                                              ### Public constructors                                                                                                                                                                                                                                                              |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| `<T : `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`> `[PagingDataPresenter](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#PagingDataPresenter(kotlin.coroutines.CoroutineContext,androidx.paging.PagingData))`(` ` mainContext: `[CoroutineContext](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html)`,` ` cachedPagingData: `[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData)`<T>?` `)` | Cmn |

|                                           ### Public functions                                           |
|----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                            | [addLoadStateListener](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#addLoadStateListener(kotlin.Function1))`(listener: (`[CombinedLoadStates](https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates)`) `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)`)` Add a[CombinedLoadStates](https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates)listener to observe the loading state of the current[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData).                                     | Cmn |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                            | [addOnPagesUpdatedListener](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#addOnPagesUpdatedListener(kotlin.Function0))`(listener: () `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)`)` Add a listener which triggers after the pages presented to the UI are updated, even if the actual items presented don't change.                                                                                                                                                                                                                                                             | Cmn |
| `suspend `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                  | [collectFrom](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#collectFrom(androidx.paging.PagingData))`(pagingData: `[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData)`<T>)`                                                                                                                                                                                                                                                                                                                                                                                                        | Cmn |
| `operator T?`                                                                                            | `@`[MainThread](https://developer.android.com/reference/kotlin/androidx/annotation/MainThread) [get](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#get(kotlin.Int))`(index: @`[IntRange](https://developer.android.com/reference/kotlin/androidx/annotation/IntRange)`(from = 0) `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns the presented item at the specified position, notifying Paging of the item access to trigger any loads necessary to fulfill[prefetchDistance](https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#prefetchDistance()). | Cmn |
| `T?`                                                                                                     | `@`[MainThread](https://developer.android.com/reference/kotlin/androidx/annotation/MainThread) [peek](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#peek(kotlin.Int))`(index: @`[IntRange](https://developer.android.com/reference/kotlin/androidx/annotation/IntRange)`(from = 0) `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns the presented item at the specified position, without notifying Paging of the item access that would normally trigger page loads.                                                                                                            | Cmn |
| `abstract suspend `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)         | [presentPagingDataEvent](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#presentPagingDataEvent(androidx.paging.PagingDataEvent))`(event: `[PagingDataEvent](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataEvent)`<T>)` Handler for[PagingDataEvent](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataEvent)emitted by[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData).                                                                                                                                                         | Cmn |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                            | [refresh](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#refresh())`()` Refresh the data presented by this[PagingDataPresenter](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter).                                                                                                                                                                                                                                                                                                                                                                                                     | Cmn |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                            | [removeLoadStateListener](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#removeLoadStateListener(kotlin.Function1))`(listener: (`[CombinedLoadStates](https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates)`) `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)`)` Remove a previously registered[CombinedLoadStates](https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates)listener.                                                                                                                                         | Cmn |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                            | [removeOnPagesUpdatedListener](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#removeOnPagesUpdatedListener(kotlin.Function0))`(listener: () `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)`)` Remove a previously registered listener for updates to presented pages.                                                                                                                                                                                                                                                                                                               | Cmn |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                            | [retry](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#retry())`()` Retry any failed load requests that would result in a[LoadState.Error](https://developer.android.com/reference/kotlin/androidx/paging/LoadState.Error)update to this[PagingDataPresenter](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter).                                                                                                                                                                                                                                                                       | Cmn |
| [ItemSnapshotList](https://developer.android.com/reference/kotlin/androidx/paging/ItemSnapshotList)`<T>` | [snapshot](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#snapshot())`()` Returns a new[ItemSnapshotList](https://developer.android.com/reference/kotlin/androidx/paging/ItemSnapshotList)representing the currently presented items, including any placeholders if they are enabled.                                                                                                                                                                                                                                                                                                                                    | Cmn |

|                                                                                                              ### Public properties                                                                                                              |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| [StateFlow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/index.html)`<`[CombinedLoadStates](https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates)`?>` | [loadStateFlow](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#loadStateFlow()) A hot[Flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html)of[CombinedLoadStates](https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates)that emits a snapshot whenever the loading state of the current[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData)changes. | Cmn |
| [Flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html)`<`[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)`>`                                       | [onPagesUpdatedFlow](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#onPagesUpdatedFlow()) A hot[Flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html)that emits after the pages presented to the UI are updated, even if the actual items presented don't change.                                                                                                                                                  | Cmn |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                     | [size](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#size())                                                                                                                                                                                                                                                                                                                                                                                                                      | Cmn |

## Public constructors

### PagingDataPresenter

Cmn  

```
<T : Any> PagingDataPresenter(
    mainContext: CoroutineContext = Dispatchers.Main,
    cachedPagingData: PagingData<T>? = null
)
```  

|                                                                      Parameters                                                                       |
|-------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mainContext: `[CoroutineContext](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html)` = Dispatchers.Main` | The coroutine context that core Paging operations will run on. Defaults to[Dispatchers.Main](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-main.html). Main operations executed within this context include but are not limited to: 1. flow collection on a[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData)for Loads, LoadStateUpdate etc. 2. emitting[CombinedLoadStates](https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates)to the[loadStateFlow](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#loadStateFlow()) 3. invoking LoadState and PageUpdate listeners 4. invoking[presentPagingDataEvent](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#presentPagingDataEvent(androidx.paging.PagingDataEvent)) |
| `cachedPagingData: `[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData)`<T>? = null`                              | a[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData)that will initialize this PagingDataPresenter with any LoadStates or loaded data contained within it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |

## Public functions

### addLoadStateListener

Cmn  

```
fun addLoadStateListener(listener: (CombinedLoadStates) -> Unit): Unit
```

Add a[CombinedLoadStates](https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates)listener to observe the loading state of the current[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData).

As new[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData)generations are submitted and displayed, the listener will be notified to reflect the current[CombinedLoadStates](https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates).

When a new listener is added, it will be immediately called with the current[CombinedLoadStates](https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates), unless this[PagingDataPresenter](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter)has not been hooked up to a[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData)yet, and thus has no state to emit.  

```kotlin
import androidx.paging.LoadState

val adapter = UserPagingAdapter()
adapter.addLoadStateListener {
    // show a retry button outside the list when refresh hits an error
    retryButton.isVisible = it.refresh is LoadState.Error

    // swipeRefreshLayout displays whether refresh is occurring
    swipeRefreshLayout.isRefreshing = it.refresh is LoadState.Loading

    // show an empty state over the list when loading initially, before items are loaded
    emptyState.isVisible = it.refresh is LoadState.Loading && adapter.itemCount == 0
}
```  

|                                                                                                 Parameters                                                                                                 |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
| `listener: (`[CombinedLoadStates](https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates)`) `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [LoadStates](https://developer.android.com/reference/kotlin/androidx/paging/LoadStates)listener to receive updates. |

|                                                                        See also                                                                         |
|---------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [removeLoadStateListener](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#removeLoadStateListener(kotlin.Function1)) |   |

### addOnPagesUpdatedListener

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

```
fun addOnPagesUpdatedListener(listener: () -> Unit): Unit
```

Add a listener which triggers after the pages presented to the UI are updated, even if the actual items presented don't change.

An update is triggered from one of the following:

- [collectFrom](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#collectFrom(androidx.paging.PagingData))is called and initial load completes, regardless of any differences in the loaded data

- A[Page](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page)is inserted

- A[Page](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page)is dropped

|                                            Parameters                                             |
|---------------------------------------------------------------------------------------------------|-------------------------------------------|
| `listener: () `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | called after pages presented are updated. |

|                                                                             See also                                                                              |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [removeOnPagesUpdatedListener](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#removeOnPagesUpdatedListener(kotlin.Function0)) |   |

### collectFrom

Cmn  

```
suspend fun collectFrom(pagingData: PagingData<T>): Unit
```  

### get

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

```
@MainThread
operator fun get(index: @IntRange(from = 0) Int): T?
```

Returns the presented item at the specified position, notifying Paging of the item access to trigger any loads necessary to fulfill[prefetchDistance](https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#prefetchDistance()).  

|                                                                                        Parameters                                                                                         |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------|
| `index: @`[IntRange](https://developer.android.com/reference/kotlin/androidx/annotation/IntRange)`(from = 0) `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Index of the presented item to return, including placeholders. |

| Returns |
|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `T?`    | The presented item at position[index](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#get(kotlin.Int)),`null`if it is a placeholder. |

### peek

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

```
@MainThread
fun peek(index: @IntRange(from = 0) Int): T?
```

Returns the presented item at the specified position, without notifying Paging of the item access that would normally trigger page loads.  

|                                                                                        Parameters                                                                                         |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------|
| `index: @`[IntRange](https://developer.android.com/reference/kotlin/androidx/annotation/IntRange)`(from = 0) `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Index of the presented item to return, including placeholders. |

| Returns |
|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `T?`    | The presented item at position[index](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#peek(kotlin.Int)),`null`if it is a placeholder |

### presentPagingDataEvent

Cmn  

```
abstract suspend fun presentPagingDataEvent(event: PagingDataEvent<T>): Unit
```

Handler for[PagingDataEvent](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataEvent)emitted by[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData).

When a[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData)is submitted to this PagingDataPresenter through[collectFrom](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#collectFrom(androidx.paging.PagingData)), page loads, drops, or LoadStateUpdates will be emitted to presenters as[PagingDataEvent](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataEvent)through this method.

Presenter layers that communicate directly with[PagingDataPresenter](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter)should override this method to handle the[PagingDataEvent](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataEvent)accordingly. For example by diffing two[PagingDataEvent.Refresh](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataEvent.Refresh)lists, or appending the inserted list of data from[PagingDataEvent.Prepend](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataEvent.Prepend)or[PagingDataEvent.Append](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataEvent.Append).  

### refresh

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

```
fun refresh(): Unit
```

Refresh the data presented by this[PagingDataPresenter](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter).

[refresh](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#refresh())triggers the creation of a new[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData)with a new instance of[PagingSource](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource)to represent an updated snapshot of the backing dataset. If a[RemoteMediator](https://developer.android.com/reference/kotlin/androidx/paging/RemoteMediator)is set, calling[refresh](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#refresh())will also trigger a call to[RemoteMediator.load](https://developer.android.com/reference/kotlin/androidx/paging/RemoteMediator#load(androidx.paging.LoadType,androidx.paging.PagingState))with[LoadType](https://developer.android.com/reference/kotlin/androidx/paging/LoadType#REFRESH)to allow[RemoteMediator](https://developer.android.com/reference/kotlin/androidx/paging/RemoteMediator)to check for updates to the dataset backing[PagingSource](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource).

Note: This API is intended for UI-driven refresh signals, such as swipe-to-refresh. Invalidation due repository-layer signals, such as DB-updates, should instead use[PagingSource.invalidate](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#invalidate()).  

```kotlin
import androidx.appcompat.app.AppCompatActivity
import androidx.paging.LoadState

class MyActivity : AppCompatActivity() {
    private lateinit var binding: MyActivityBinding
    private val pagingAdapter = UserPagingAdapter()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = MyActivityBinding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.recyclerView.adapter = pagingAdapter
        pagingAdapter.addLoadStateListener { loadStates ->
            binding.swipeRefreshLayout.isRefreshing = loadStates.refresh is LoadState.Loading
        }

        binding.swipeRefreshLayout.setOnRefreshListener { pagingAdapter.refresh() }
    }
}
```  

|                                                See also                                                |
|--------------------------------------------------------------------------------------------------------|---|
| [invalidate](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#invalidate()) |   |

### removeLoadStateListener

Cmn  

```
fun removeLoadStateListener(listener: (CombinedLoadStates) -> Unit): Unit
```

Remove a previously registered[CombinedLoadStates](https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates)listener.  

|                                                                                                 Parameters                                                                                                 |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------|
| `listener: (`[CombinedLoadStates](https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates)`) `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | Previously registered listener. |

|                                                                     See also                                                                      |
|---------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [addLoadStateListener](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#addLoadStateListener(kotlin.Function1)) |   |

### removeOnPagesUpdatedListener

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

```
fun removeOnPagesUpdatedListener(listener: () -> Unit): Unit
```

Remove a previously registered listener for updates to presented pages.  

|                                            Parameters                                             |
|---------------------------------------------------------------------------------------------------|---------------------------------|
| `listener: () `->` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | Previously registered listener. |

|                                                                          See also                                                                           |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [addOnPagesUpdatedListener](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#addOnPagesUpdatedListener(kotlin.Function0)) |   |

### retry

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

```
fun retry(): Unit
```

Retry any failed load requests that would result in a[LoadState.Error](https://developer.android.com/reference/kotlin/androidx/paging/LoadState.Error)update to this[PagingDataPresenter](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter).

Unlike[refresh](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#refresh()), this does not invalidate[PagingSource](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource), it only retries failed loads within the same generation of[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData).

[LoadState.Error](https://developer.android.com/reference/kotlin/androidx/paging/LoadState.Error)can be generated from two types of load requests:

- [PagingSource.load](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#load(androidx.paging.PagingSource.LoadParams))returning[PagingSource.LoadResult.Error](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Error)

- [RemoteMediator.load](https://developer.android.com/reference/kotlin/androidx/paging/RemoteMediator#load(androidx.paging.LoadType,androidx.paging.PagingState))returning[RemoteMediator.MediatorResult.Error](https://developer.android.com/reference/kotlin/androidx/paging/RemoteMediator.MediatorResult.Error)

### snapshot

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

```
fun snapshot(): ItemSnapshotList<T>
```

Returns a new[ItemSnapshotList](https://developer.android.com/reference/kotlin/androidx/paging/ItemSnapshotList)representing the currently presented items, including any placeholders if they are enabled.

## Public properties

### loadStateFlow

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

```
val loadStateFlow: StateFlow<CombinedLoadStates?>
```

A hot[Flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html)of[CombinedLoadStates](https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates)that emits a snapshot whenever the loading state of the current[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData)changes.

This flow is conflated. It buffers the last update to[CombinedLoadStates](https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates)and immediately delivers the current load states on collection, unless this[PagingDataPresenter](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter)has not been hooked up to a[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData)yet, and thus has no state to emit.  

```kotlin
import androidx.lifecycle.lifecycleScope
import androidx.paging.LoadState

val adapter = UserPagingAdapter()
lifecycleScope.launch {
    adapter.loadStateFlow
        .map { it.refresh }
        .distinctUntilChanged()
        .collectLatest {
            // show a retry button outside the list when refresh hits an error
            retryButton.isVisible = it is LoadState.Error

            // swipeRefreshLayout displays whether refresh is occurring
            swipeRefreshLayout.isRefreshing = it is LoadState.Loading

            // show an empty state over the list when loading initially, before items are loaded
            emptyState.isVisible = it is LoadState.Loading && adapter.itemCount == 0
        }
}
```  

### onPagesUpdatedFlow

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

```
val onPagesUpdatedFlow: Flow<Unit>
```

A hot[Flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html)that emits after the pages presented to the UI are updated, even if the actual items presented don't change.

An update is triggered from one of the following:

- [collectFrom](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataPresenter#collectFrom(androidx.paging.PagingData))is called and initial load completes, regardless of any differences in the loaded data

- A[Page](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page)is inserted

- A[Page](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page)is dropped

Note: This is a[SharedFlow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/index.html)configured to replay 0 items with a buffer of size 64. If a collector lags behind page updates, it may trigger multiple times for each intermediate update that was presented while your collector was still working. To avoid this behavior, you can[conflate](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/index.html)this[Flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html)so that you only receive the latest update, which is useful in cases where you are simply updating UI and don't care about tracking the exact number of page updates.  

### size

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

```
val size: Int
```  

|                                   Returns                                   |
|-----------------------------------------------------------------------------|----------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Total number of presented items, including placeholders. |