On an Android application which must works offline most of the time I need, when it's online, to do some synchronous operations but Firebase always take the value from the cache when I need the value in the servor , Here a exemple
Query query = FirebaseDatabase.getInstance().getReference()
.child("Post")
.child(UserChannel)
.child("Post");
query.keepSynced(false);
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
Log.d(TAG, "Posts founded" );
for(DataSnapshot snapshot: dataSnapshot.getChildren()){
Posts thepost= snapshot.getValue(Posts.class);
Log.d(TAG, "Post found");
ListPosts.add(thepost);
}
}else {
Log.d(TAG, " no post could be found.");
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException(); // don't ignore errors
}
});
Here I use addListenerForSingleValueEvent for load posts from a specific user , it works fine but if the user add a new post in the child and I try to reload all his posts , the new post wont be loaded . I assume Firebase load the post from the cache how can I bypass this the cache to load only from servor ?