-3

I'm a newbie of programming Android apps, specially using Firebase platform. I have to store two different values into two different children of the same root node on a Firebase RealTime Database. I'm using the setValue() method but the problem is that the first invocation works, while the second one doesn't have effect. I paste the relative part of code hoping it will be useful for a better view of the environment. Did I make any mistake?

public Boolean store() {
    mDatabase = FirebaseDatabase.getInstance().getReference();
    mDatabase.child("posts").push().setValue(this); //it has effect
    mDatabase.child("groups").push().setValue(this.author); //it hasn't effect
    return true;
}
  • What exactly is `this.author`? Log it or step through debug to find out. – Doug Stevenson Feb 21 '18 at 21:22
  • @DougStevenson it's a private variable of the class to whom the methods belongs. I've already logged it with `Log.d(TAG, this.author)` and the output is right. – m.caggiano Feb 22 '18 at 00:08
  • Is it null? That value won't write - there are no "empty" locations in Realtime Database. Do you have security rules set up at all? – Doug Stevenson Feb 22 '18 at 00:10
  • @DougStevenson no, it's not null, the output is the value that the variable should have. The only rule which is set is that users must be authenticated to have permissions of read/write on db (and the user is correctly signed in, in fact it writes in 'posts' node but not in 'groups' one). – m.caggiano Feb 22 '18 at 08:23

1 Answers1

0

Maybe try to make a Hashmap to push two values

HashMap<String, String> dataMap = new HashMap<String, String>();
            dataMap.put("posts", this);
            dataMap.put("groups", this.author);

and then push it with a addOnCompleteListener

mDatabase.push().setValue(dataMap)
Karim Chaari
  • 340
  • 1
  • 8