I'm working on the android app and I have a problem when trying to read products data from firebase. I need these product name, product price and product description data to use in recycler view.

When I tried to run the code I didn't get this data.
I tried the given code:
ProductsRef = FirebaseDatabase.getInstance().getReference().child("Products");
ProductsRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
productItems = getAllItems(dataSnapshot);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w( "Failed to read value.", error.toException());
}
});
public ArrayList<Products> getAllItems(DataSnapshot dataSnapshot){
items = new ArrayList<Products>();
for (DataSnapshot item : dataSnapshot.getChildren()) {
items.add(new Products(
item.child("category").getValue().toString(),
item.child("description").getValue().toString(),
item.child("date").getValue().toString(),
item.child("image").getValue().toString(),
item.child("pid").getValue().toString(),
item.child("pname").getValue().toString(),
item.child("price").getValue().toString(),
item.child("time").getValue().toString()
));
}
return items;
}
onDataChangeand run the code in a debugger, does it get triggered? If so, step through the code, and see what line doesn't work. My educated guess is that you're trying to access the data before it is loaded, but there's not enough information in your question to be sure. If that is the case, see stackoverflow.com/questions/50434836/…productItemsoutside theonDataChange()method. Please check the duplicates to see why do you have this behaviour and how can you solve this using a custom callback.