How to move Firebase child from one node to another in Android?

前端 未结 4 1991
渐次进展
渐次进展 2020-11-30 08:09

I am working on a project where user request for our valet services and on the other end valet accepts request.

I am using using Firebase as backend and on request c

4条回答
  •  庸人自扰
    2020-11-30 08:47

    you can listen to value event on your child you want to copy it ,, and #onDataChange get reference of new child and set value dataSnapshot to this child like below sample code

    FirebaseDatabase.getInstance().getReference("childYouWantToCopy")
                        .addListenerForSingleValueEvent(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                        FirebaseDatabase.getInstance().getReference("ChildCopyTo").setValue(dataSnapshot.getValue());
                    }
    
                    @Override
                    public void onCancelled(@NonNull DatabaseError databaseError) {
    
                    }
                });
    

提交回复
热议问题