Skip to content

Instantly share code, notes, and snippets.

@kenny-io
Created October 12, 2017 00:03
Show Gist options
  • Save kenny-io/ead8f92bc3697c2b33f6f7a01c1e98b3 to your computer and use it in GitHub Desktop.
Save kenny-io/ead8f92bc3697c2b33f6f7a01c1e98b3 to your computer and use it in GitHub Desktop.
private void addRealtimeUpdate() {
DocumentReference contactListener = db.collection("PhoneBook").document("Contacts");
contactListener.addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(DocumentSnapshot documentSnapshot, FirebaseFirestoreException e) {
if (e != null ){
Log.d("ERROR", e.getMessage());
return;
}
if (documentSnapshot != null && documentSnapshot.exists()){
Toast.makeText(MainActivity.this, "Current data:" + documentSnapshot.getData(), Toast.LENGTH_SHORT).show();
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment