I'm facing an problem with my app. When the user registers in the app, automatticaly it is created a "profile" of the user in a database, where the Uid is the child:
After the Login in the app is the app calls the activity2. On start it is suppost to load the user information into a class:
{
tUsers.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.child(fauth.getUid()).child("uBirthday").exists()) {
}
else {
//userData is created when activity2 is called
userData= (snapshot.child(fauth.getUid()).getValue(Class_UserData.class));
Log.i("MainActivity inside", "User: " + userData.getUserName() + " Email: " + userData.getUserEmail());
}
}
@Override
public void onCancelled (@NonNull DatabaseError error){
return;
}
});
Below Class_UserData:
String uName;
String uEmail;
String UserBirthday;
String UserGender;
int UserPhoto;
public Class_UserData(String userName, String userEmail) {
uName = userName;
uEmail = userEmail;
}
public Class_UserData(String userName, String userEmail, String userBirthday, String userGender) {
uName = userName;
uEmail = userEmail;
UserBirthday = userBirthday;
UserGender = userGender;
}
public Class_UserData() {
}
public void setUserName(String userName) {
uName = userName;
}
public void setUserEmail(String userEmail) {
uEmail = userEmail;
}
public void setUserBirthday(String userBirthday) {
UserBirthday = userBirthday;
}
public void setUserGender(String userGender) {
UserGender = userGender;
}
public String getUserName() {
return uName;
}
public String getUserEmail() {
return uEmail;
}
public String getUserBirthday() {
return UserBirthday;
}
public String getUserGender() {
return UserGender;
}
}
When inside the onDataChange the class is working. OutSide the class it returns null. Any ideas how to solve this?