Here is current simple description my app. It uses some remote server API, which uses standart HTTP session. Login activity. It calls auth class, passing login and password.
public class Auth extends AsyncTask{
...
private DefaultHttpClient client = new DefaultHttpClient();
private HttpContext localContext = new BasicHttpContext();
private CookieStore cookieStore = new BasicCookieStore();
...
public void auth(String login, String password) {
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpPost request = new HttpPost(url);
...
}
protected void onPostExecute(Boolean result){
parent.loginresponse(result)
}
成功验证时, 远程服务器创建了 sardart HTTP 会话, 发送给我 cookie, 保存在 CookiStore 中 。 登录后, 登录响应开始主活动 。 在那里, 我希望所有 API 请求都有一个通用类 。
我如何正确保存登录后在所有活动之间创建的HTTP会话信息,并将其传递给相应的API方法所需的功能?