如何在 Android 中将 Firebase 子节点从一个节点移动到另一个节点? [英] How to move Firebase child from one node to another in Android?

查看:30
本文介绍了如何在 Android 中将 Firebase 子节点从一个节点移动到另一个节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个项目,用户请求我们的代客服务,而另一端的代客接受请求.

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

我使用 Firebase 作为后端,并根据请求将客户 uid 保存在请求"子项上.

I am using using Firebase as backend and on request customer uid is save on 'request' child.

当代客接受请求时,客户 uid 应从请求"节点移动到进行中"节点.

When valet accepts request, customer uid should move from 'request' node to 'on progress' node.

我该怎么做?

推荐答案

我推荐使用这个:

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

        @Override
        public void onCancelled(FirebaseError firebaseError)
        {
            System.out.println("Copy failed");
        }
    });
}

这来自这个来源:https://gist.github.com/katowulf/6099042 .我在 JavaEE 代码和 Android 应用中多次使用它.

This come from this source : https://gist.github.com/katowulf/6099042 . I used it several times in my JavaEE code and also in my android app.

您传递了 fromPath 和 toPath.这是抄袭,不是搬家,所以原件也会留在原来的地方.如果你想删除,你可以在 System.out.println("Success"); 之后的 fromPath 上做一个设置值;.

You pass your fromPath and toPath. This is a copy tought and not a move, so the original will remain at his original place too. If you would like to delete, you can do a set value on the fromPath just after the System.out.println("Success"); .

这篇关于如何在 Android 中将 Firebase 子节点从一个节点移动到另一个节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆