I have a loop that calls the getComments method for each Facebook object as shown, the getComments method is not called from anywhere else in the program.
JSONArray feedArr = response.getGraphObject().getInnerJSONObject().getJSONArray("data");
for (int i=0;i<feedArr.length();i++) {
JSONObject obj = feedArr.getJSONObject(i);
getComments(obj.getString("id"));
}
From what I see, I am making a new Request object each time, but I still get the error "java.lang.IllegalStateException: Cannot execute task: the task is already running."
each time.
private void getComments(final String post) {
String fqlQuery = "{" +
"'comments':'SELECT fromid, text, id, likes, time, user_likes FROM comment WHERE post_id=\""
+ post + "\" LIMIT 2000'," +
"'users':'SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT fromid FROM #comments)'" +
"}";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Session session = Session.getActiveSession();
new Request(session,
"/fql",
params,
HttpMethod.GET,
new Request.Callback(){
public void onCompleted(Response response) {
//..parsing data
}
}).executeAsync();
}
}
Is there a reason why this happens and how can I fix it?