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

前端 未结 4 1993
渐次进展
渐次进展 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:59

    As of compile firebase-database:11.0.1, this is the same function with the new class references (https://firebase.google.com/support/guides/firebase-android July 05 2017)

    private void moveGameRoom(final DatabaseReference fromPath, final DatabaseReference toPath) {
            fromPath.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    toPath.setValue(dataSnapshot.getValue(), new DatabaseReference.CompletionListener() {
                        @Override
                        public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) {
                            if (firebaseError != null) {
                                System.out.println("Copy failed");
                            } else {
                                System.out.println("Success");
    
                            }
                        }
                    });
    
                }
    
                @Override
                public void onCancelled(DatabaseError databaseError) {
    
                }
            });
        }
    

提交回复
热议问题