I am trying to develop a multiplayer game which integrates google as well as facebook login. My game logic is that as soon as a person logs in through any platform then i should automatically add all his friends(who have played the game) from that social platform to app42 buddies. Since google gives only one list of friends therefore, i need to find out for each of the friend whether he/she has played the game. I am pasting the code below.
public void addFriends(){
if(obj.myFriend != null && !obj.myFriend.isEmpty()){
app42RequestType = ACCEPT_FRIEND_REQUEST;
senders = new FriendRequestSender[obj.myFriend.size()];
acceptors = new FriendRequestAcceptor[obj.myFriend.size()];
Log.v(LoginPage.TAG, "sending friend request to : " + obj.myFriend.size() + " friends. ");
int i = 0;
String searchString;
for (SpellUpUser mUser : obj.myFriend){
i++;
searchString = "%" + mUser.getUserId() + "%";
Log.v(LoginPage.TAG, "searching for user : " + searchString);
HashMap<String, String> otherMetaHeaders = new HashMap<String, String>();
otherMetaHeaders.put("like", searchString);
userService.setOtherMetaHeaders(otherMetaHeaders);
senders[i - 1] = new FriendRequestSender(i, mUser.getUserId());
userService.getAllUsers(senders[i - 1]);
}
}
}
//the inner class for listening to the response
private class FriendRequestSender implements App42CallBack{
private int counter;
private String friendName;
ArrayList<User> searchedUsers;
private FriendRequestSender(int counter, String friendName){
this.counter = counter;
this.friendName = friendName;
this.searchedUsers = null;
Log.v(LoginPage.TAG, "friendName to send request : " + this.friendName);
}
@Override
public void onException(Exception e) {
App42UserInitializer.this.counter = this.counter;
Log.v(LoginPage.TAG, "the user " + this.friendName + "has not played the game yet. you can invite him/her");
}
@Override
public void onSuccess(final Object response) {
this.searchedUsers = (ArrayList<User>)response;
friendsFound.add(this.searchedUsers.get(0).getUserName());
Log.v(LoginPage.TAG, response.toString());
Log.v(LoginPage.TAG, this.searchedUsers.size() + " : my friend username is : " + this.friendName);
}
}
The Logcat
03-27 16:11:19.890: V/tag(16278): sending friend request to : 3 friends.
03-27 16:11:19.890: V/tag(16278): searching for user : %113195432701725509290%
03-27 16:11:19.890: V/tag(16278): friendName to send request : 113195432701725509290
03-27 16:11:19.890: V/tag(16278): searching for user : %109099365556900661884%
03-27 16:11:19.890: V/tag(16278): friendName to send request : 109099365556900661884
03-27 16:11:19.890: V/tag(16278): searching for user : %101513042965188424205%
03-27 16:11:19.890: V/tag(16278): friendName to send request : 101513042965188424205
03-27 16:11:21.130: V/tag(16278): [{"app42":{"response":{"success":true,"users":{"user":{"userName":"g_101513042965188424205","email":"husain707@gmail.com","createdOn":"2015-03-26T07:48:52.000Z","accountLocked":false,"profile":{"firstName":"","lastName":"","sex":null,"dateOfBirth":null,"mobile":null,"officeLandLine":null,"homeLandLine":null,"line1":null,"line2":null,"city":null,"state":null,"pincode":null,"country":null}}}}}}]
03-27 16:11:21.130: V/tag(16278): 1 : my friend username is : 109099365556900661884
03-27 16:11:21.130: V/tag(16278): friendName to accept request : g_101513042965188424205
03-27 16:11:21.160: V/tag(16278): [{"app42":{"response":{"success":true,"users":{"user":{"userName":"g_109099365556900661884","email":"mahtabhussain7@gmail.com","createdOn":"2015-03-27T09:42:17.000Z","accountLocked":false,"profile":{"firstName":"","lastName":"","sex":null,"dateOfBirth":null,"mobile":null,"officeLandLine":null,"homeLandLine":null,"line1":null,"line2":null,"city":null,"state":null,"pincode":null,"country":null}}}}}}]
03-27 16:11:21.160: V/tag(16278): 1 : my friend username is : 113195432701725509290
03-27 16:11:21.160: V/tag(16278): friendName to accept request : g_109099365556900661884
03-27 16:11:21.230: V/tag(16278): [{"app42":{"response":{"success":true,"users":{"user":{"userName":"g_101513042965188424205","email":"husain707@gmail.com","createdOn":"2015-03-26T07:48:52.000Z","accountLocked":false,"profile":{"firstName":"","lastName":"","sex":null,"dateOfBirth":null,"mobile":null,"officeLandLine":null,"homeLandLine":null,"line1":null,"line2":null,"city":null,"state":null,"pincode":null,"country":null}}}}}}]
03-27 16:11:21.230: V/tag(16278): 1 : my friend username is : 101513042965188424205
03-27 16:11:21.230: V/tag(16278): friendName to accept request : g_101513042965188424205
The Problem
I am not able to understand why there callbacks for some requests are getting overriden over other callbacks of other requests. Does anybody know what is the reason for this? Is there any other better way to accomplish the task?