Skip to content

Instantly share code, notes, and snippets.

@ramden
Last active December 31, 2016 23:12
Show Gist options
  • Save ramden/3addea21cf925ecd3c8c380f78679ad9 to your computer and use it in GitHub Desktop.
Save ramden/3addea21cf925ecd3c8c380f78679ad9 to your computer and use it in GitHub Desktop.
// ##############################################################################
// Scenario 1:
// ##############################################################################
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
FirebaseDatabase.getInstance().goOffline(); // <--------NOTE THIS
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.child("users").child(App.get().getUid()).child("items").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// THIS IS NOT FIRING
}
@Override
public void onCancelled(DatabaseError databaseError) {
...
}
});
// ##############################################################################
// After Scenario 1 I change code to this and run:
// ##############################################################################
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
FirebaseDatabase.getInstance().goOnline(); // <--------NOTE THIS
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.child("users").child(App.get().getUid()).child("items").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// THIS IS FIRING. ALL GOOD
}
@Override
public void onCancelled(DatabaseError databaseError) {
...
}
});
// ##############################################################################
// After this I change code to following and it works
// ##############################################################################
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
FirebaseDatabase.getInstance().goOffline(); // <--------NOTE THIS
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.child("users").child(App.get().getUid()).child("items").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// THIS IS FIRING. ALL GOOD
}
@Override
public void onCancelled(DatabaseError databaseError) {
...
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment