【问题标题】:How to add new key-value pair in MutableData during Firebase Transaction in Android?如何在 Android 的 Firebase 事务期间在 MutableData 中添加新的键值对?
【发布时间】:2016-03-02 13:55:12
【问题描述】:

我需要在 Android 中通过事务添加一个新的键值对。有什么办法吗?

【问题讨论】:

    标签: android firebase firebase-realtime-database


    【解决方案1】:

    您在doTransaction() 中获得的MutableData 对象有一个child() 方法,可用于读取/写入子数据。

    ref.runTransaction(new Transaction.Handler() {
      @Override
      public Transaction.Result doTransaction(MutableData currentData) {
        currentData.child("my new child").setValue(1);
        return Transaction.success(currentData);
      }
      @Override
      public void onComplete(FirebaseError firebaseError, boolean committed, DataSnapshot currentData) {
        //This method will be called once with the results of the transaction.
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-23
      • 2016-09-30
      • 1970-01-01
      • 2023-01-17
      • 2013-09-28
      • 2019-11-01
      相关资源
      最近更新 更多