Skip to content

Instantly share code, notes, and snippets.

@benhaxe
Last active November 21, 2017 16:48
Show Gist options
  • Save benhaxe/a2abd258758e04d3b4dda27e2d0c2fc6 to your computer and use it in GitHub Desktop.
Save benhaxe/a2abd258758e04d3b4dda27e2d0c2fc6 to your computer and use it in GitHub Desktop.
A short code to add user to fire base database, with expanation
public class User(){
public String username;
public String email;
public void User(){
}
public void User(String username, String email){
this.username = username;
this.email = email;
}
private void writeNewUser(String userId, String name, String email) {
User user = new User(name, email);
// The [users] is the root node and the [userId] the the setValue method is to add the object Users to the nde with the uderId.
mDatabase.child("users").child(userId).setValue(user);
/*Assume you are to change a users username then, here we are being specific*/
mDatabase.child("users").child(userId).child("username").setValue(name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment