I have many question about this part. at first this is my code:
private void getUserDetails(UserObject mContact) {
DatabaseReference mUserDB = FirebaseDatabase.getInstance().getReference().child("user");
Query query = mUserDB.orderByChild("phone").equalTo(mContact.getPhone());
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
String phone = "",
name = "";
for(DataSnapshot childSnapshot : dataSnapshot.getChildren()){
if(childSnapshot.child("phone").getValue()!=null)
phone = childSnapshot.child("phone").getValue().toString();
if(childSnapshot.child("name").getValue()!=null)
name = childSnapshot.child("name").getValue().toString();
UserObject mUser = new UserObject(childSnapshot.getKey(), name, phone);
if (name.equals(phone))
for(UserObject mContactIterator : contactList){
if(mContactIterator.getPhone().equals(mUser.getPhone())){
mUser.setName(mContactIterator.getName());
}
}
userList.add(mUser);
mUserListAdapter.notifyDataSetChanged();
return;
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
my first question: when and why do we use query?
my second question: what does orderByChild method and equalTo method do?
my third question: Is query like data snapShot or something like that and what kind of data it holds in itself?
my 4 question: what does query.addListenerForSingleValueEvent do and when the code inside that run? I know it runs when there is change (for onDataChange method) but I don't what change is it for example is it change in my user list in Firebase or in my realtime database in Firebase.
my 5 question : what does Query query = mUserDB.orderByChild("phone").equalTo(mContact.getPhone()); do? and what will happen if we doesn't use method equelTo?
my 6 question: what would happen if we use Lod.d("print" , query.toString())
excuse me for having a lot of questions about this but I am a beginner in android and java and I don't how should I solve this problem.
if it is possible for you please answer my question.
thanks for reading my question and sorry if there is any typic problem.
thanks a lot again.