I am making and application that show a first screen with a bunch of randomly picked data from a node in Firebase database.
To present user with different data every
There is no direct way provided by firebase database but you can do this using Collections.shuffle()
What i did was,Take the snapshot and store it in an arraylist.
private ArrayList array=new ArrayList<>();
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot imageSnapshot : dataSnapshot.getChildren()) {
MyClass myclass = imageSnapshot.getValue(MyClass.class);
array.add(myclass.someFunction());
}
}
Then call the shuffle method on this array list.
Collections.shuffle(array); // randomize the arraylist
Now you can do whatever you want with this randomized arraylist.