Last active
November 21, 2017 16:48
-
-
Save benhaxe/a2abd258758e04d3b4dda27e2d0c2fc6 to your computer and use it in GitHub Desktop.
A short code to add user to fire base database, with expanation
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 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