I have an ArrayList of userIds and I want to fetch every user where userId is in that ArrayList. I don't want to use for loop and to make request for every userId in the list. Is there an option to send ArrayList as a parameter and to get list of ParseObjects as a response?
5
-
what do u mean by not using a for loop?Hari Krishnan– Hari Krishnan2015-10-20 07:59:30 +00:00Commented Oct 20, 2015 at 7:59
-
1and from where do you want to fetch users? from a backend server? from your local db?Hari Krishnan– Hari Krishnan2015-10-20 08:01:49 +00:00Commented Oct 20, 2015 at 8:01
-
I want to fetch users from a backend serversubasa– subasa2015-10-20 08:02:58 +00:00Commented Oct 20, 2015 at 8:02
-
@HariKrishnan What I can do is to make request for every id that I have in the list by using for loop, but for sure there is a better way how to do thissubasa– subasa2015-10-20 08:05:43 +00:00Commented Oct 20, 2015 at 8:05
-
cant u send a json which have all these ids?Hari Krishnan– Hari Krishnan2015-10-20 08:13:18 +00:00Commented Oct 20, 2015 at 8:13
Add a comment
|
2 Answers
List<String> userIds = new ArrayList<>();
ParseQuery<ParseUser> userParseQuery = ParseUser.getQuery();
userParseQuery.whereContainedIn("objectId", userIds);
userParseQuery.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> objects, ParseException e) {
if (e == null){
//
} else {
//
}
}
});
Comments
I think there's a contains() method you can use if I even understand you properly. It's been a while since I did something like that but i think it has to be overridden. for example if you have ArrayList you can override the method to take an object of person as a parameter and compare a few fields of the person object then return a boolean or something like that. bus since you don't want to use a for loop then I guess you will just have to use a for-each loop then