Code example for AccountManager

Methods: getAuthToken, invalidateAuthToken

0
                onAuthenticationFinished(loginCallback, result);
            } 
        }; 
 
        if (activity != null) {
            accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, null, activity, c, null);
        } else { 
            accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, true, c, null);
        } 
    } 
 
    private void onAuthenticationFinished( 
            final LoginCallback loginCallback, AccountManagerFuture<Bundle> result) {
        assert result.isDone();
        try { 
            final String authToken = result.getResult().getString(AccountManager.KEY_AUTHTOKEN);
            onAuthenticationFinished(loginCallback, null, authToken);
        } catch (Exception ex) {
            onAuthenticationFinished(loginCallback, ex, null);
        } 
    } 
 
	private void invalidateSession() { 
		final String authToken = getSettings().getAuthToken();
		if (authToken != null) {
			accountManager.invalidateAuthToken(MANAGED_ACCOUNT_TYPE, authToken);
		} 
		getSettings().setAccountName(null); 
		getApp().authenticate(null); 
	}