[ACCEPTED]-Clear cookies in Android-android

Accepted answer
Score: 34
    CookieSyncManager.createInstance(this); 
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookies(callback);

0

Score: 7
@SuppressWarnings("deprecation")
public void clearCookies(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { 
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else {
        CookieSyncManager cookieSyncMngr= CookieSyncManager.createInstance(context);
        cookieSyncMngr.startSync();
        CookieManager cookieManager= CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();
        cookieSyncMngr.sync();
    }
}

0

Score: 0

Use a CookieManager instance to manage cookies 3 in your app. Probably in a custom Application class.

mCookieManager = new CookieManager();
mCookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(mCookieManager); 

And 2 whenever you want to clear, call a method 1 like the one below:

public static void clearCookies() {
mCookieManager.getCookieStore().removeAll();
}

More Related questions