Search code examples
androidkotlinandroid-roomandroid-paging-library

Room Paging library always return null LiveData?


I am trying to use a paging library in my project but when I try to recieve LiveData<PageList<Entity>> data it's value is always null. My implementation looks like this:

DAO

@Query("SELECT * FROM entity")
fun getAll(): DataSource.Factory<Int, Entity>

ViewModel

    val pagedListConfig = PagedList.Config.Builder()
            .setEnablePlaceholders(false)
            .setPageSize(20).build()

    val data = LivePagedListBuilder(database.getAll(), pagedListConfig)
                .build()
                .value

The data variable is always null.


Solution

  • Very simple, you're still working LiveData, so it should be just:

    val data = LivePagedListBuilder(database.getAll(), pagedListConfig).build()
    

    Then data is LiveData which you should observe.