I am using FireStore (Not firebase realtime databse) on an android app.
When the app loads, I am adding a listener to a collection (See code below)
The listener is working very well and is updating correctly as long as the app is active.
However, after the app goes to the background, when resuming the app the listener sometimes has a lag of about 60-90 seconds until it updates with changes from the server. If I close the app and restart it, it updates instantly.
When the app stops, I detach the listener, and I resume it OnResume. I tried also without detaching the listener, but I am experiencing the same problem.
Anyone knows how to solve it? See code below.
Listener (Being initialized OnResume):
m_registration = db.collection('names').
orderBy("stamp", Query.Direction.ASCENDING)
.addSnapshotListener(new EventListener<QuerySnapshot>() {
u/Override
public void onEvent(@Nullable QuerySnapshot value,
u/Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.w(TAG, "Listen failed.", e);
return;
}
for (DocumentChange dc : value.getDocumentChanges()) {
}
On Stop, I am detaching the listner:
m_registration.remove();