Thanks for your research, I was looking for the same issue because I want to keep a PHP session. I think AQuery should be able to handle the cookies by it self and I still don't understand why we must set the cookies in the callback and not in the AQuery instance. Otherwise we should be forced to use the AjaxCallback anytime we need to handle the cookies :-/
By the way, here is a another sample based on your research. First we need a variable to save the cookie info:
List<Cookie> cookies;
Next we make the JSON call:
AQuery query = new AQuery(this);
query.ajax("your url", JSONObject.class, new AjaxCallback<String>() {
@Override
public void callback(String url, String json, AjaxStatus status) {
cookies = status.getCookies(); // We are saving the cookies in our variable
}
});
After we save the cookie data we could use it in the next requests:
AQuery query = new AQuery(this);
AjaxCallback<JSONObject> ajaxCallback = new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, String json, AjaxStatus status) {
cookies = status.getCookies(); // Save the cookies in every requests you made
}
}
for (Cookie cookie : cookies) {
ajaxCallback.cookie(cookie.getName(), cookie.getValue());
//Here we are setting the cookie info.
}
query.ajax("your url", JSONObject.class, ajaxCallback);
Thanks again poslinski.