小编Ana*_*and的帖子

即使在应用程序关闭或通过按下android中的菜单按钮放入后台后,如何在Android中持久存储cookie?

您好先生我是Android的新手,并希望持续cookie,直到用户点击signout.but目前我使用默认Cookiemanger几小时后删除cookie,我的应用程序变得反应迟钝所以应用程序无法进一步认证调用服务器获取数据和应用程序死亡.

我已经看到很多代码并使用cookie存储来保持cookie活着,但我失败了.我无法理解在哪里编写代码,这样每次我打电话给服务器然后cookie自动进入服务器.

这是我的代码:

public class PersistentCookieStore implements CookieStore {

/**
 * The default preferences string.
 */
private final static String PREF_DEFAULT_STRING = "";

/**
 * The preferences name.
 */
private final static String PREFS_NAME = PersistentCookieStore.class.getName();

/**
 * The preferences session cookie key.
 */
private final static String PREF_SESSION_COOKIE = "session_cookie";

private CookieStore mStore;
private Context mContext;

/**
 * @param context The application context
 */
public PersistentCookieStore(Context context) {
    // prevent context leaking by getting the application context
    mContext = …
Run Code Online (Sandbox Code Playgroud)

cookies android session-cookies cookiestore

7
推荐指数
0
解决办法
732
查看次数

标签 统计

android ×1

cookies ×1

cookiestore ×1

session-cookies ×1