title: How to delete a node from the firebase real-time database after creating another node with same IDs
body: <p>I am trying to delete a node requests when the accept option of the alert dialog is clicked,and also when the node contacts created successfully. What I am getting however is that the node contact is being created as expected, but the node requests is not.
  <a href="https://i.stack.imgur.com/KN7JQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KN7JQ.png" alt="enter image description here" /></a></p>
  <p>This is the code that I am using..
  Database references</p>
  <pre><code>joinRequestsRef =  FirebaseDatabase.getInstance().getReference().child(&quot;questions posts&quot;).child(postid).child(&quot;group&quot;).child(groupname).child(&quot;requests&quot;).child(currentUserID);
      usersRef = FirebaseDatabase.getInstance().getReference(&quot;users&quot;);
      contactsRef = FirebaseDatabase.getInstance().getReference().child(&quot;questions posts&quot;).child(postid).child(&quot;group&quot;).child(groupname).child(&quot;contacts&quot;)/*.child(currentUserID)*/;
  
  FirebaseRecyclerOptions&lt;Users&gt; options = new FirebaseRecyclerOptions.Builder&lt;Users&gt;()
              .setQuery(joinRequestsRef, Users.class)
              .build();
  
      FirebaseRecyclerAdapter&lt;Users, RequestsViewHolder&gt; adapter = new FirebaseRecyclerAdapter&lt;Users, RequestsViewHolder&gt;(options) {
          @Override
          protected void onBindViewHolder(@NonNull final RequestsViewHolder holder, int position, @NonNull Users model) {
  
              holder.itemView.findViewById(R.id.user_requests_accept_button).setVisibility(View.VISIBLE);
              holder.itemView.findViewById(R.id.user_requests_reject_button).setVisibility(View.VISIBLE);
  
              final String list_user_id = getRef(position).getKey();
              DatabaseReference getTypeRef = getRef(position).child(&quot;request_type&quot;).getRef();
  
              getTypeRef.addValueEventListener(new ValueEventListener() {
                  @Override
                  public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                      if (dataSnapshot.exists()){
                        String type = Objects.requireNonNull(dataSnapshot.getValue()).toString();
                        if (type.equals(&quot;received&quot;)) {
                            assert list_user_id != null;
                            usersRef.child(list_user_id).addValueEventListener(new ValueEventListener() {
                                @Override
                                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                                   if (dataSnapshot.exists()) {
                                       String requestFullName = Objects.requireNonNull(dataSnapshot.child(&quot;name&quot;).getValue()).toString();
                                       String requestProfileImage = Objects.requireNonNull(dataSnapshot.child(&quot;profilepictureurl&quot;).getValue()).toString();
  
                                       holder.fnTextView.setText(requestFullName);
                                       Glide.with(getApplication()).load(requestProfileImage).into(holder.imageView);
  
                                   }
                                   holder.itemView.setOnClickListener(new View.OnClickListener() {
                                       @Override
                                       public void onClick(View v) {
                                           CharSequence[] options = new CharSequence[]{&quot;accept&quot;, &quot;cancel&quot;};
  
                                           AlertDialog.Builder builder = new AlertDialog.Builder(JoinRequestsActivity.this);
                                           builder.setTitle(&quot;Join Request&quot;);
  
                                           builder.setItems(options, new DialogInterface.OnClickListener() {
                                               @Override
                                               public void onClick(DialogInterface dialog, int which) {
                                                   if (which == 0){
                                                       contactsRef.child(currentUserID).child(list_user_id).child(&quot;contact&quot;).setValue(&quot;saved&quot;).addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
                                                           @Override
                                                           public void onComplete(@NonNull Task&lt;Void&gt; task) {
                                                               if (task.isSuccessful()){
                                                                   contactsRef.child(list_user_id).child(currentUserID).child(&quot;contact&quot;).setValue(&quot;saved&quot;).addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
                                                                       @Override
                                                                       public void onComplete(@NonNull Task&lt;Void&gt; task) {
                                                                           if (task.isSuccessful()){
                                                                               joinRequestsRef.child(currentUserID).child(list_user_id).removeValue().addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
                                                                                   @Override
                                                                                   public void onComplete(@NonNull Task&lt;Void&gt; task) {
                                                                                       if (task.isSuccessful()){
                                                                                           joinRequestsRef.child(list_user_id).child(currentUserID).removeValue().addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
                                                                                               @Override
                                                                                               public void onComplete(@NonNull Task&lt;Void&gt; task) {
                                                                                                   if (task.isSuccessful()){
                                                                                                       Toast.makeText(JoinRequestsActivity.this, &quot;Participator added&quot;, Toast.LENGTH_SHORT).show();
                                                                                                   }
                                                                                               }
                                                                                           });
                                                                                       }
                                                                                   }
                                                                               });
                                                                           }
                                                                       }
                                                                   });
                                                               }
                                                           }
                                                       });
                                                   }
                                                   if (which == 1){
                                                       joinRequestsRef.child(currentUserID).child(list_user_id).removeValue().addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
                                                           @Override
                                                           public void onComplete(@NonNull Task&lt;Void&gt; task) {
                                                               if (task.isSuccessful()){
                                                                   joinRequestsRef.child(list_user_id).child(currentUserID).removeValue().addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
                                                                       @Override
                                                                       public void onComplete(@NonNull Task&lt;Void&gt; task) {
                                                                           if (task.isSuccessful()){
                                                                               Toast.makeText(JoinRequestsActivity.this, &quot;Participator Deleted&quot;, Toast.LENGTH_SHORT).show();
                                                                           }
                                                                       }
                                                                   });
                                                               }
                                                           }
                                                       });
                                                   }
                                               }
                                           });
  
                                           builder.show();
                                       }
                                   });
                                }
  
                                @Override
                                public void onCancelled(@NonNull DatabaseError databaseError) {
  
                                }
                            });
                        }
  
                  }
  
                  }
  
                  @Override
                  public void onCancelled(@NonNull DatabaseError databaseError) {
  
                  }
              });
          }
  </code></pre>
  <p>Any help will be appreciated</p>