Firebase Android How To Get Query of Objects With Key List

458 Views Asked by At

I have a list of object keys that correspond to objects in my FB database. I want to retrieve all of those objects in an efficient way but I couldn't figure out how to query them.

For now I am using this code. It's just a recursive method that retrieves the objects one by one until they are all found. It can be very slow.

private void getNextPoll(){
        pollRef = rootRef.child(getString(R.string.poll_ref)).child(myPollIds.get(polls.size()));
        pollRef.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                Poll poll = dataSnapshot.getValue(Poll.class);

                polls.add(poll);

                System.out.println(poll);

                //if this is the last poll, then sort the polls by date and display them
                if(polls.size() == myPollIds.size()){
                    //Done

                    //sort

                    //display
                    recyclerView.setAdapter(new MyPollsListAdapter(getContext(), polls));
                }else{
                    getNextPoll();
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                Log.e(TAG, databaseError.getMessage());
            }
        });
    }

My database is organized like so:

How should I go about doing this?

Thanks in advance :)

0

There are 0 best solutions below