title: How to check if a value exists already in a Firebase and get key in android
body: <p>In my android application, when the user logs in, I need to check my realtime database to determine if the users ID exists within this database. Once the users ID has been located, i then need to retrieve the parent node of this ID in order to determine if the user logging in is a customer or employee. I'm having some difficulties coding this, as i'm relatively new to using firebase.</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>final String user_id = Objects.requireNonNull(firebaseAuth.getCurrentUser()).getUid();
  
  DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
  ValueEventListener eventListener = new ValueEventListener()
  {
      @Override
      public void onDataChange(DataSnapshot dataSnapshot)
      {
          for(DataSnapshot ds : dataSnapshot.getChildren())
          {
              if(ds.child(user_id).exists())
              {
                  //check if employee or customer?
                  String cust_or_emp =  ds.child(user_id).getKey();
                  Log.d("test1",String.valueOf(ds.child(user_id).getKey()));
                  if (cust_or_emp.equals("Customers"))
                  {
                              name= Objects.requireNonNull(ds.child(user_id).child("User_Information").child("firstName").getValue()).toString();
                              Log.e("first name is ", "firstname :" + name);
                              toNextActivity = new Intent(getActivity(), MainActivity.class);
                              toNextActivity.putExtra("name",name);
                              Log.e("2first name is ", "firstname :" + name);
                              progressBarLayout2.setVisibility(View.GONE);
                              Objects.requireNonNull(getActivity()).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
                              Objects.requireNonNull(getActivity()).startActivity(toNextActivity);
                              getActivity().finish();
                  } else if (cust_or_emp.equals("Employee")) {
                      //code for if the key is employee
                  }
              }
          }
      }
  
      @Override
      public void onCancelled(@NonNull DatabaseError databaseError)
      {
          Log.d("error", databaseError.getMessage()); //Don't ignore errors!
      }
  };
  rootRef.addListenerForSingleValueEvent(eventListener);
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/4IT7d.png" alt="database model"></p>
  
  <p>Currently when I run my application, nothing appears to happen.</p>