How to retrieve data from a Firebase database with Kotlin?

Viewed 15442

This is the model I upload on Firebase:

public class OnlineMatch{

private User user1;
private User user2;

public OnlineMatch(User firstPlayer, User secondPlayer) {
        this.user1 = firstPlayer;
        this.user2 = secondPlayer;
    }

}

Then I send data to Firebase in this way (kotlin):

 fun createMatch(match: OnlineMatch) {
        val matchList = database.child("multiplayer").push()
        matchList.setValue(match)
    }

Thus, my DB structure is the following:

enter image description here If I expand a node I can see perfectly my objects: OnlineMatch(User1, User2)

Now I would like to query the db and obtain an ArrayList'<'OnlineMatch'>'. I have already found the Firebase docs but I found nothing useful. How can I do? Thanks in advance.

1 Answers
Related