How to logout from Twitter account with android application

android

#1

i want to logout user’s twitter account from android application

below is the code i tried but not working

            CookieSyncManager.createInstance(Setting.this);
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.removeSessionCookie();
            Twitter.getSessionManager().clearActiveSession();
            Twitter.logOut();

#2

Hey @saltafshaikh,

Can you share the Logcat output when you’re trying to Logout the user? Also, which version of Twitter Kit are you using?

-Mike


#3

**below code worked for me **

public void logoutTwitter() {
    TwitterSession twitterSession = TwitterCore.getInstance().getSessionManager().getActiveSession();
    if (twitterSession != null) {
        ClearCookies(getApplicationContext());
        Twitter.getSessionManager().clearActiveSession();
        Twitter.logOut();
    }
}

public static 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();
    }
}

IOS API loginWithCompletion and logout