I'm trying to make a search query using firebase and it works really well.
Query searchQuery = usersRef.orderByChild(child).startAt(text).endAt(text + "\uf8ff").limitToFirst(limit);
searchQuery.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//search result logic
}
@Override
public void onCancelled(DatabaseError databaseError) {}
});
I have enabled offline capabilities because in need them in my app and here is my problem: this ValueEventListener keep listening on the local stored datas while I need to keep it always updated... it's a search query.
I don't think keepSynced(true) applied to the users reference would be a nice idea because this reference is huge and this will cause lot of internet and memory waste.
I've red on web that using addValueEventListener instead of addListenerForSingleValueEvent query will always receive updated answers from the server, without look in local stored data. This could be a way to solve my problem but I need to listen data ONCE and this will keep listen for datas so should I stop this listener if I decide to use it?
Please help me with some ideas and sorry for my scholastic English.