Disclaimer: I made this question and answer it myself because I need a "bigger board" to answer extended question of this post (as this whole explanation is never going to fit in comment
I'm having this data:
{
"users" : {
"randomUserId" : {
"books" : {
"booksId1" : true,
"booksId2" : true
}
}
},
"books" : {
"booksId1" : {
"title" : "Awesome Book"
},
"booksId2" : {
"title" : "Harry Potter"
}
}
}
I know I have to get users/randomUserId/books
first then loop the dataSnapshot
result to get all the book ids. Then I have to request detail data on each book id by using database reference that point to books/bookId?/
. Something like this:
rootRef.child("users/" + user.getUid() + "books").addListenerForSingleValueEvent(new ValueEventListener() {
... onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot bookIdSnapshot : dataSnapshot) {
rootRef.child("books/" + bookIdSnapshot.getValue(String.class))
.addListenerForSingleValueEvent(...) {
// here i get the book detail data
}
}
}
...
}
But with that code, each rootRef.child("books/"...)
will be executed separately. So how can I know if the data have completely acquired?