I'm building an app using Firestore as my backend. I need to get every new change from database.
Code
EventListener<DocumentSnapshot> listener = new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot snapshot, @Nullable FirebaseFirestoreException e) {
if (snapshot != null && snapshot.exists()) {
DataClass dataClass = snapshot.toObject(DataClass.class);
processesData(dataClass); // process data from db.
}
}
};
ListenerRegistration listenerReg = dataDocumentReference.addSnapshotListener(listener);
When I close the application, the app is still getting the data.
I read that I can close the connection. How can I do that?