0

I am trying to understand what the initialKey does in the Pager constructor, but I cannot find any sort of explanation, not even in the official documentation:

https://developer.android.com/reference/kotlin/androidx/paging/Pager#%3Cinit%3E(androidx.paging.PagingConfig,%20androidx.paging.Pager.Key,%20androidx.paging.RemoteMediator,%20kotlin.Function0)

enter image description here


Can anyone explain what it does or how it works and how to use it?

Shadow
  • 4,168
  • 5
  • 41
  • 72
  • https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page#nextKey:androidx.paging.PagingSource.LoadResult.Page.Key Seems to be the page you want to start the pagination from. `null` by default – Eselfar Nov 18 '20 at 05:37
  • @Eselfar Thanks, but it is not clear what it refers to nor how it can be used. Is it the number of a page to load directly, the number of the items' position in the paged list, etc. – Shadow Nov 18 '20 at 20:50

1 Answers1

2

After testing I believe the initialKey param is meant to indicate a position in the list, not a page.

I did two tests with varying page sizes.

Table with 2000 entries

Page sizes

  • 10
  • 20
  • 100
  • 123

For each page size I used the following as the initialKey for an item at position X

  • initialKey = X
    • this uses the item position as the initialKey
  • initialKey = X / page size
    • this uses the page in which the item is part of

For all results the item would always be correctly loaded in the initial/first chunk of data when I used the initialKey = X. It always failed when I used it as page size.

I am not sure if this is conclusive, but this was my conclusion from the limited tests for my problem.

Shadow
  • 4,168
  • 5
  • 41
  • 72