I want to show all object from every Relation in following Query. But it still empty. I tried with the this Code, but it did not work. I hope someone can help me. Thanks in advance
mData = new ArrayList<>();
ParseQuery<ParseObject> receiver = ParseQuery.getQuery("Group");
receiver.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> feed, ParseException e) {
if (e == null) {
mData = feed;
for (int i = 0; i < mData.size(); i++) {
ParseRelation<ParseObject> relation = mData.get(i).getRelation("Data");
ParseQuery<ParseObject> query = relation.getQuery();
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
rData = objects;
Log.e("APP", String.valueOf(rData.size()));
Log.d("APP", "mData" + mData.size());
if (mSwipeStack.getAdapter() == null) {
mAdapter = new SwipeAdapter(getContext(), rData);
mSwipeStack.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
Log.d("mAdapter", "Loaded");
}
}, 4000);
//mSwipeStack.setListener(getActivity());
Log.i("APP", "We found messages!");
}
}
});
}
}
}
});
Sorry for my bad english :)
I suggest you to use pointers and not relations (in your case) and i will explain why:
It is not best practice to run findInBackground in a loop because if your dataset (mData) size will be large you will execute mData.size calls to the server and this is not a best practice and also not scalable. I suggest you to use Pointer Arrays (you can read more about it here) by using arrays you will need only one service call to get all the data to your client (this way your solution will be more scalable and much more simple)
So your new solution (if you will decide to go with it of course :)) will be the following:
And then your code will look like the following:
EDIT1 - use getList
ParseQuery<ParseObject> receiver = ParseQuery.getQuery("Group");
reciever.include("data");
receiver.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> feed, ParseException e) {
// in here you can access all the data which under group in the following way:
for (int i=0;i < feed.size();i++){
ParseObject obj = feed.get(i);
// here you have all the data collection
List<ParseObject> dataItems = obj.getList("data");
// now you can loop on dataItems
}
}
});
Please note there is a chance that my code is not 100% accurate but i hope you got the idea.
Good Luck :)