Last active
March 23, 2018 18:50
-
-
Save sjmach/3e97dc7b775709127a5911d130b7e525 to your computer and use it in GitHub Desktop.
Saving user data in Cloud Firestore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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