Skip to content

Instantly share code, notes, and snippets.

@sjmach
Last active March 23, 2018 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjmach/3e97dc7b775709127a5911d130b7e525 to your computer and use it in GitHub Desktop.
Save sjmach/3e97dc7b775709127a5911d130b7e525 to your computer and use it in GitHub Desktop.
Saving user data in Cloud Firestore
public static void addNewUser(String name, String email, String id, String type){
Map<String, Object> newContact = new HashMap<>();
newContact.put(NAME_KEY, name);
newContact.put(EMAIL_KEY, email);
newContact.put(ID_KEY, id);
newContact.put(TYPE, type);
db = FirebaseFirestore.getInstance();
db.collection("Users").document(id).set(newContact)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
//Do something on success, maybe fire a successful analytics event
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
//Do something on failure, maybe fire a failure analytics event
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment