1

I'm trying to show the user profiles of various users like tinder but I was wondering will the firebase always shows the user who registered first to other new users or if the iteration is random which will guarantee that the result will be random and everyone chances of getting displayed are equal? If not does someone knows how to make it random in android? How I'm doing it is

FirebaseDatabase.getInstance().getReference().child("Users").child(OppositeUserSex);

Edit This is the code where I think sorting wouldn't help because I want it to be random

 if(mAuth.getCurrentUser().isEmailVerified())
    {
        FirebaseDatabase.getInstance().getReference().child("Users").child(UserSex).child(currentUserID).child("isVerified").setValue(true);
    }
    DatabaseReference oppositeSexDB= FirebaseDatabase.getInstance().getReference().child("Users").child(OppositeUserSex);
    System.out.println(OppositeUserSex + "oppositeUser");
    oppositeSexDB.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(@NonNull @NotNull DataSnapshot snapshot, @Nullable @org.jetbrains.annotations.Nullable String previousChildName) {
            if(snapshot.exists())
            {
                if(!snapshot.child("Selection").child("Nah").hasChild(currentUserID)) {
                    if(snapshot.child("Url").exists() && snapshot.child("isVerified").exists()) {    //If user has image only then show them else dont display them && if they are verified
                        items.add(new ItemModel(snapshot.child("Url").getValue().toString(), snapshot.child("Name").getValue().toString(), "", "", snapshot.getKey()));
                    }
                    adapter.notifyDataSetChanged();
                }
            }
        }
CS Learner
  • 21
  • 4

2 Answers2

0

Firebase doesn't guarantee that unless you enforce it with the query you make with "orderBy" and also need to specify the direction of sorting / ordering there.

Please have a look here: Order and Limit data with Firebase

So, basically pull the data the way you want it (which would save processing in Android. And if you cannot fully achieve it in query, then you may have to do the additional filtering / ordering in Android code (Java / Kotlin).

Please don't hesitate to ask if you have any more doubts on this. Thanks.

arun
  • 308
  • 2
  • 11
0

To my experience it shows in the order of when the data was inserted, but I wouldn't rely on that, I always define the fields I will use for sorting and retrieve sorted data based using them.

I bookmarked this video sometime ago, it might have all the answers you need Sort and Filter Firebase Data