DataSnapshot get one user info every time - android

I receive FirebaseUser Id & email how signed in correctly as shown in debug screenshot , but DataSnapshot ds is always loaded with user_01 info , I tried hard to solve this problem and found Similar questions on the site but couldn't help . so can anyone help to solve this ?
public class AddToDatabase extends AppCompatActivity {
private static final String TAG = "AddToDatabase";
private ListView userInfolist;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
String userId;
UserInformations uInfo = new UserInformations();
DatabaseReference myRef;
FirebaseDatabase mFirebaseDatabase;
FirebaseUser user;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_to_database);
userInfolist = (ListView) findViewById(R.id.userInfolist);
mAuth = FirebaseAuth.getInstance();
mFirebaseDatabase = FirebaseDatabase.getInstance();
myRef = mFirebaseDatabase.getReference();
user = mAuth.getCurrentUser();
userId = user.getUid();
mAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
toastMassege(" You are successfly signed in with " + user.getEmail());
} else {
Log.d(TAG, "onAuthStateChanged:signed_out");
toastMassege(" You are successfly signed out ");
}
}
};
myRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
showData(dataSnapshot);
}
#Override
public void onCancelled(DatabaseError error) {
}
});
}
Boolean signedstate = true;
private void showData(DataSnapshot dataSnapshot) {
ArrayList<String> arrayList = new ArrayList<>();
for (DataSnapshot ds : dataSnapshot.getChildren()) {
if (signedstate) {
uInfo.setName(ds.getValue(UserInformations.class).getName());
uInfo.setEmail(ds.getValue(UserInformations.class).getEmail());
uInfo.setPhone_num(ds.getValue(UserInformations.class).getPhone_num());
arrayList.add(uInfo.getName());
arrayList.add(uInfo.getEmail());
arrayList.add(uInfo.getPhone_num());
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, arrayList);
userInfolist.setAdapter(adapter);
toastMassege("its Done ");
signedstate = false;
}
}
}
#Override
public void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
#Override
public void onStop() {
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
private void toastMassege(String massege) {
Toast.makeText(this, massege, Toast.LENGTH_SHORT).show();
}
}
this is class UserInformations :
class UserInformations {
public String email,name,phone_num ;
UserInformations() {
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone_num() {
return phone_num;
}
public void setPhone_num(String phone_num) {
this.phone_num = phone_num;
}
}

Your problem is that you are creating the adapter inside the for loop. In order to solve your problm, you need to move this line:
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, arrayList);
outside the for loop because you are creating a new instance of ArrayAdapter every time you iterate. Please use the following code:
private void showData(DataSnapshot dataSnapshot) {
ArrayList<String> arrayList = new ArrayList<>();
for (DataSnapshot ds : dataSnapshot.getChildren()) {
if (signedstate) {
uInfo.setName(ds.getValue(UserInformations.class).getName());
uInfo.setEmail(ds.getValue(UserInformations.class).getEmail());
uInfo.setPhone_num(ds.getValue(UserInformations.class).getPhone_num());
arrayList.add(uInfo.getName());
arrayList.add(uInfo.getEmail());
arrayList.add(uInfo.getPhone_num());
signedstate = false;
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, arrayList);
userInfolist.setAdapter(adapter);
toastMassege("its Done ");
}

Related

How to retrieve data from one child

In my firebase two child generated one is "Users" and second is "Redeem" in users section registration form is saved and points are also saved and in redeem user send data for redeem the points my problem is that when I tried to retrieve data from "Users" then automatically data is merged of "Users" and "Redeem" .maybe this happened because "Users" and "Redeem" have same "UID" of current user now my main point is there is any way to show the data in same activity "Users" and "Redeem" separately in text view.
public class redeem extends AppCompatActivity {
TextView textname,textemail,textnumber,texttotalpoits;
EditText editname,editemail,editpaytmnumber,editredeempoints,edittotalpoints;
Button submitbtn;
private FirebaseDatabase mFirebaseDatabase;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private DatabaseReference myRef;
private String userID;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.redeem);
submitbtn = findViewById(R.id.submiybtn);
textname = findViewById(R.id.textname);
textemail = findViewById(R.id.textemail);
textnumber = findViewById(R.id.textnumber);
texttotalpoits = findViewById(R.id.texttotalpoints);
editname = findViewById(R.id.editname);
editemail = findViewById(R.id.editemail);
editpaytmnumber = findViewById(R.id.editpaytmnumber);
editredeempoints = findViewById(R.id.editredeempoints);
edittotalpoints = findViewById(R.id.edittotalpoints);
mAuth = FirebaseAuth.getInstance();
mFirebaseDatabase = FirebaseDatabase.getInstance();
myRef = mFirebaseDatabase.getReference();
FirebaseUser user = mAuth.getCurrentUser();
userID = user.getUid();
mAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
}
};
myRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
showData(dataSnapshot);
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
submitbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String name = editname.getText().toString().trim();
final String email = editemail.getText().toString().trim();
final String number = editpaytmnumber.getText().toString().trim();
final String points = edittotalpoints.getText().toString().trim();
final String redeempoints = editredeempoints.getText().toString().trim();
if (name.isEmpty()) {
editname.setError(getString(R.string.input_error_email));
editname.requestFocus();
return;
}
if (email.isEmpty()) {
editemail.setError(getString(R.string.input_error_email));
editemail.requestFocus();
return;
}
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
editemail.setError(getString(R.string.input_error_email_invalid));
editemail.requestFocus();
return;
}
if (number.isEmpty()) {
editpaytmnumber.setError("Please Enter Paytm Number");
editpaytmnumber.requestFocus();
return;
}
int number1 = Integer.parseInt(texttotalpoits.getText().toString());
int number2 = Integer.parseInt(editredeempoints.getText().toString());
if (number2 > number1){
editredeempoints.setError("You Have No Enough Points");
editredeempoints.setText("");
}
RedeemInfromation redeemInfromation = new RedeemInfromation(
name,
email,
number,
points,
redeempoints
);
FirebaseDatabase.getInstance().getReference("redeem")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(redeemInfromation);
}
});
}
public void showData(DataSnapshot dataSnapshot){
for (DataSnapshot ds : dataSnapshot.getChildren()){
UserInformation uInfo = new UserInformation();
uInfo.setName(ds.child(userID).getValue(UserInformation.class).getName());
uInfo.setEmail(ds.child(userID).getValue(UserInformation.class).getEmail());
uInfo.setNumber(ds.child(userID).getValue(UserInformation.class).getNumber());
uInfo.setPoints(ds.child(userID).getValue(UserInformation.class).getPoints());
textname.setText("" + uInfo.getName());
textemail.setText("" + uInfo.getEmail());
textnumber.setText("" + uInfo.getNumber());
texttotalpoits.setText("" + uInfo.getPoints());
edittotalpoints.setText("" + uInfo.getPoints());
}
}
#Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
#Override
protected void onStop() {
super.onStop();
mAuth.removeAuthStateListener(mAuthListener);
}
}

Retrieve specific data from firebase

I'm new to firebase, I tried to look into the documentation and youtube but just couldn't figure it out.
I have a simple id and display_name structure database in firebase:
AppName{
users{
HzIYTbIbSzSlinF1Aa52WYUcD4E2{
display_name: "Greg Nks"
}
}
And I want the data to get into a User object, with Id(string) and display_name(string)
I tried to test my retrieving data, but I cant get it.
this is my code:
public void initializeVariables(View view){
mToolBar = view.findViewById(R.id.users_appBar);
usersRv = view.findViewById(R.id.friends_list_rv);
mLayoutManager= new LinearLayoutManager(view.getContext());
myDataset = new ArrayList<>();
mAuth = FirebaseAuth.getInstance();
mFirebaseDatabase = FirebaseDatabase.getInstance();
myRef = mFirebaseDatabase.getReference();
mAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if(user!=null){
}
}
};
myRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
//remember it will called in the start of the fragment
showData(dataSnapshot); //TODO fix the reading from firebase
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
public void showData(DataSnapshot dataSnapshot){
User u= dataSnapshot.getValue(User.class);
u=null;
}
Thanks!
Class User {
private String display_name;
private String userKey;
public User(){
}
public User(String name,String key){
display_name = name;
userKey = key;
}
public void setDisplay_name(Sring name)
{
display_name = name;
}
public String getDisplay_name()
{
return display_name;
}
public void setUserKey(Sring key)
{
userKey = key;
}
public String getUserKey()
{
return userKey;
}
}
now change this statment
User u= dataSnapshot.getValue(User.class);
by this :
String key = datasnapshot.getKey();
String name = datasnapshot.child('display_name').getValue().toString();
User user = new User(name, key);

Populating a sub-group in firebase Database

I have an activity where i want to send a custom message to a sub-group in my database when a button is clicked. I tried to check for a user_id and send the message to those user id's, My problem is that when i click the button(status) it only sends that message to one person.
This is my Activity:
public class messageActivity extends AppCompatActivity {
private Button status;
private DatabaseReference mRootRef;
private String mCurrentUserId;
private String userName;
private String user_id;
private String message;
private FirebaseAuth mAuth;
private DatabaseReference mUserRef;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
FirebaseApp.initializeApp(this);
mRootRef = FirebaseDatabase.getInstance().getReference();
mAuth = FirebaseAuth.getInstance();
gettingIntent();
status = (Button)findViewById(R.id.rescue);
status.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view)
{
addUpdateMessage();
addTeamUpdateChat();
Toast.makeText(getApplicationContext(), "Team Update message was successfully sent",Toast.LENGTH_LONG).show();
}
});
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Status");
toolbar.setTitleTextColor(android.graphics.Color.WHITE);
if (mAuth.getCurrentUser() != null) {
mUserRef = FirebaseDatabase.getInstance().getReference().child("Users").child(mAuth.getCurrentUser().getUid());
mUserRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
userName = dataSnapshot.child("name").getValue().toString();
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
private void checkUser() {
if (mCurrentUserId == null) {
sendToStart();
}else{
Toast.makeText(getApplicationContext(), "Logged in",Toast.LENGTH_SHORT).show();
}
}
private void gettingIntent() {
Intent intent =getIntent();
user_id = intent.getStringExtra("user_id");
}
private void addTeamUpdateChat() {
String current_user_ref="Team_Updates/"+mCurrentUserId+"/"+user_id;
String reciever_user_ref= "Team_Updates/"+user_id+"/"+mCurrentUserId;
DatabaseReference team_push_key = mRootRef.child("Emergency_Messages").child(mCurrentUserId).child(user_id).push();
String push_key = team_push_key.getKey();
Map messageMap = new HashMap();
messageMap.put("userName", userName + " Is now a new Member of the team.");
messageMap.put("type","text");
messageMap.put("from",mCurrentUserId);
messageMap.put("seen",false);
messageMap.put("time", ServerValue.TIMESTAMP);
Map messageUserMap = new HashMap();
messageUserMap.put(current_user_ref+ "/"+push_key,messageMap);
messageUserMap.put(reciever_user_ref+ "/"+push_key,messageMap);
mRootRef.updateChildren(messageUserMap, new DatabaseReference.CompletionListener() {
#Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
if(databaseError!=null){
Log.d("TAG",databaseError.getMessage().toString());
}
}
});
}
private void addUpdateMessage() {
mRootRef.child("Team_Updates_Chat").child(mCurrentUserId).addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(!dataSnapshot.hasChild(user_id)){
Map chatAddMap = new HashMap();
chatAddMap.put("seen",false);
chatAddMap.put("timestamp", ServerValue.TIMESTAMP);
Map chatUserMap = new HashMap();
chatUserMap.put("Team_Updates_Chat/"+mCurrentUserId+"/"+user_id, chatAddMap);
chatUserMap.put("Team_Updates_Chat/"+user_id+"/"+mCurrentUserId, chatAddMap);
mRootRef.updateChildren(chatUserMap, new DatabaseReference.CompletionListener() {
#Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
if(databaseError!= null){
Toast.makeText(MenuActivity.this, "Error: "+databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
#Override
public void onStart() {
super.onStart();
FirebaseUser currentUser = mAuth.getCurrentUser();
if(currentUser == null){
sendToStart();
} else{
mCurrentUserId = mAuth.getCurrentUser().getUid();
}
}
#Override
protected void onStop() {
super.onStop();
}
private void sendToStart() {
Intent startIntent = new Intent(messageActivity.this, Home.class);
startActivity(startIntent);
finish();
}
}
I'm Still learning Programming in Android Studio, Is there Any suggestions on how i should approach this?
You are sending a message only to single user because you are getting only a single user. To send a message to multiple users, you need to loop to get all those users and then send the message to all of them.

arrayList always loaded with user info from Firebase database regardless of which user is signed in?

In showdata method witch load FirebaseUser info when I run the app and signed in with any user , arrayList in the method is always loaded with User_03 info ,
debugging show that:
DataSnapshot ds is loaded with right value of signed in user ( right key and info ) .
uInfo ( the object which carry signed in user info) loaded with right data from database .
uInfo.setName(ds.getValue(UserInformations.class).getName()); = undefined .
I think there is something wrong in arryList size .
the attached screen shot I take it when arrive to breakpoint in line : toastMassege("it's Done") .
public class AddToDatabase extends AppCompatActivity {
private static final String TAG = "AddToDatabase";
private ListView userInfolist ;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
String userId;
UserInformations uInfo =new UserInformations();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_to_database);
userInfolist = (ListView) findViewById(R.id.userInfolist);
mAuth = FirebaseAuth.getInstance();
FirebaseDatabase mFirebaseDatabase = FirebaseDatabase.getInstance();
DatabaseReference myRef = mFirebaseDatabase.getReference();
FirebaseUser user = mAuth.getCurrentUser();
userId = user.getUid();
mAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
toastMassege(" You are successfly signed in with " +
user.getEmail());
} else {
Log.d(TAG, "onAuthStateChanged:signed_out");
toastMassege(" You are successfly signed out ");
}
}
};
myRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
showData(dataSnapshot);
}
#Override
public void onCancelled(DatabaseError error) {
}
});
}
private void showData(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()){
uInfo.setName(ds.getValue(UserInformations.class).getName());
uInfo.setEmail(ds.getValue(UserInformations.class).getEmail());
uInfo.setPhone_num(ds.getValue(UserInformations.class).getPhone_num());
ArrayList<String> arrayList=new ArrayList<>();
int listSize = arrayList.size();
arrayList.add(uInfo.getName());
arrayList.add(uInfo.getEmail());
arrayList.add(uInfo.getPhone_num());
ArrayAdapter<String> adapter =new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,arrayList);
userInfolist.setAdapter(adapter);
toastMassege("its Done ");
}
}
#Override
public void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
#Override
public void onStop() {
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
private void toastMassege(String massege) {
Toast.makeText(this, massege, Toast.LENGTH_SHORT).show();
}
}
this is class UserInformations
class UserInformations {
public String email,name,phone_num ;
UserInformations() {
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone_num() {
return phone_num;
}
public void setPhone_num(String phone_num) {
this.phone_num = phone_num;
}
}
This is happening because you are have declared the ArrayList<String> arrayList=new ArrayList<>(); inside the for loop. This means that you are creating a new instance of ArrayList class every time you iterate.
In order to solve this, just move the decration outside for loop like this:
private void showData(DataSnapshot dataSnapshot) {
ArrayList<String> arrayList=new ArrayList<>(); //Moved outside
for(DataSnapshot ds : dataSnapshot.getChildren()){
uInfo.setName(ds.getValue(UserInformations.class).getName());
uInfo.setEmail(ds.getValue(UserInformations.class).getEmail());
uInfo.setPhone_num(ds.getValue(UserInformations.class).getPhone_num());
int listSize = arrayList.size();
arrayList.add(uInfo.getName());
arrayList.add(uInfo.getEmail());
arrayList.add(uInfo.getPhone_num());
ArrayAdapter<String> adapter =new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,arrayList);
userInfolist.setAdapter(adapter);
toastMassege("its Done ");
}
}

Load FirebaseUser info gives null value

In showdata method witch load FirebaseUser info I have null value for uInfo , I run the app and signed in with User_02 , debugging show that :
ds.getChild(userId ) reach to the right user who signed in and loaded with right key , but when try to get value from UserInformations.class gives me NullPointerException ,so what the mistake in the coade ?
I not that ds have key and value for User_01 . is that normal ?
public class AddToDatabase extends AppCompatActivity {
private static final String TAG = "AddToDatabase";
private ListView userInfolist ;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
String userId;
UserInformations uInfo =new UserInformations();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_to_database);
userInfolist = (ListView) findViewById(R.id.userInfolist);
mAuth = FirebaseAuth.getInstance();
FirebaseDatabase mFirebaseDatabase = FirebaseDatabase.getInstance();
DatabaseReference myRef = mFirebaseDatabase.getReference();
FirebaseUser user = mAuth.getCurrentUser();
userId = user.getUid();
mAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
toastMassege(" You are successfly signed in with " + user.getEmail());
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
toastMassege(" You are successfly signed out ");
}
}
};
// Read from the database
myRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
showData(dataSnapshot);
}
#Override
public void onCancelled(DatabaseError error) {
// Failed to read value
}
});
}
private void showData(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()){
uInfo.setName(ds.child(userId).getValue(UserInformations.class).getName()); // set the name
uInfo.setEmail(ds.child(userId).getValue(UserInformations.class).getEmail()); // set the Email
uInfo.setPhone_num(ds.child(userId).getValue(UserInformations.class).getPhone_num()); // set the PhonNum
ArrayList<String> arrayList =new ArrayList<>();
arrayList.add(uInfo.getName());
arrayList.add(uInfo.getEmail());
arrayList.add(uInfo.getPhone_num());
ArrayAdapter<String> adapter =new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,arrayList);
userInfolist.setAdapter(adapter);
}
}
#Override
public void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
#Override
public void onStop() {
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
private void toastMassege(String massege) {
Toast.makeText(this, massege, Toast.LENGTH_SHORT).show();
}
}
UserInformation.java
class UserInformations {
private String Email,Name,Phone_num ;
UserInformations() {
}
String getEmail() {
return Email;
}
void setEmail(String email) {
this.Email = email;
}
public String getName() {
return Name;
}
public void setName(String name) {
this.Name = name;
}
String getPhone_num() {
return Phone_num;
}
void setPhone_num(String phone_num) {
this.Phone_num = phone_num;
}
}
First, change your variables in UserInformations from private to public.
class UserInformations {
public String Email,Name,Phone_num ;
}
Second, you have to change your Firebase path from Phone number to Phone_num. Why? Well, that's because you are declaring String Phone_num inside the UserInformation.
Your current JSON:
{
"uid001": {
"Email": "user01#gmail.com",
"Name": "user01",
"Phone number": "0123456789"
},
"uid002": {
"Email": "user02#gmail.com",
"Name": "user02",
"Phone number": "0123456789"
},
}
Changed to below JSON:
{
"uid001": {
"Email": "user01#gmail.com",
"Name": "user01",
"Phone_num": "0123456789"
},
"uid002": {
"Email": "user02#gmail.com",
"Name": "user02",
"Phone_num": "0123456789"
},
}
When you used for(DataSnapshot ds : dataSnapshot.getChildren()) the ds already have the data of the child which is the user node no need for child(userId) do it directly :
uInfo.setName(ds.child("name").getValue());
uInfo.setEmail(ds.child("email").getValue());
uInfo.setPhone_num(ds.child("phone_num").getValue());

Categories

Resources