ensure User Is Logged Out using AccountManager - Android android.accounts

Android examples for android.accounts:AccountManager

Description

ensure User Is Logged Out using AccountManager

Demo Code


//package com.java2s;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerFuture;
import android.content.Context;

public class Main {
    public static void ensureUserIsLoggedOut(Context context,
            String accountType) {
        AccountManager manager = (AccountManager) context
                .getSystemService(Context.ACCOUNT_SERVICE);
        Account[] accounts = manager.getAccountsByType(accountType);
        for (Account account : accounts) {
            AccountManagerFuture<Boolean> removeAccount = manager
                    .removeAccount(account, null, null);
            waitForAccountToBeRemoved(removeAccount);
        }//from  w  w w .  j  a  v a 2  s. c o m
    }

    private static void waitForAccountToBeRemoved(
            AccountManagerFuture<Boolean> removeAccount) {
        while (!removeAccount.isDone()) {
        }
    }
}

Related Tutorials