1

I am building an app that i would like to fetch data from Firestore and display it in recyclerview as the user scrolls.

I am using FirestorePagingAdapter as described here: https://github.com/firebase/FirebaseUI-Android/tree/master/firestore#using-the-firestorepagingadapter.

This adapter does not listen for realtime changes in the database, how do I manually force a refresh using swipeRefreshLayout?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • **[This](https://stackoverflow.com/questions/50741958/how-to-paginate-firestore-with-android)** is a recommended way in which you can paginate Firestore queries and keep the realtime feature. I also recommend you take a look at this **[video](https://www.youtube.com/watch?v=KdgKvLll07s)** for a better understanding. – Alex Mamo Nov 19 '18 at 09:26
  • @AlexMamo, using the implemetation you linked to, by "keeping the real time feature" you mean I can just attach an EventListener to listen for changes in the collection? – gkanyangela Nov 20 '18 at 09:36
  • The `FirestorePagingAdapter` in the FirebaseUI library is designed to **only** get data, not to listen for realtime updates. Using my solution above, you'll be able to get realtime updates. – Alex Mamo Nov 20 '18 at 09:42
  • @AlexMamo I tried the implementation from your video. I am using it in a Fragment. It works when the Fragment loads for the very first time. If i go to another fragment, when i come back (by reloading, not by back button) then only the first page loads. I have also noticed some ArrayOutOfBoundsException with some query limits and not with others. – gkanyangela Nov 20 '18 at 20:56
  • You shouls ask another question regarding this particular issue. – Alex Mamo Nov 21 '18 at 08:57

2 Answers2

1

The FirestorePagingAdapter will load the data fresh from the database whenever it shows a new page. But beyond that it has no built-in way to refresh the data.

If you want to load fresh data for the current page, you will have to create a new FirestorePagingAdapter instance in your swipe handler. The code will be the same as how you initially instantiate that adapter. Don't forget to call stopListening()

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
0

use firebasePagingAdpater.refresh()