AccountManager删除了哪个帐户

时间:2014-04-04 09:42:16

标签: android account accountmanager

我知道AccountManageraddOnAccountsUpdatedListener()可用于获取有关帐户列表更改的通知。如果发生这种事件,框架将调用提供的OnAccountsUpdateListeneronAccountsUpdated()方法。但该方法的参数仅包含帐户列表。我怎么知道用户删除了哪个帐户?提前谢谢!

1 个答案:

答案 0 :(得分:2)

根据你想要做的事情,你可能会逃避这个:

private Set<Account> mAccountCache; // init & populated when the listener is registered

@Override
public void onAccountsUpdated(Account[] accounts) {
    // This code assumes we're only interested in removed items.
    final Set<Account> currentAccounts = new HashSet<Account>(Arrays.asList(accounts));
    final Set<Account> removedAccounts = new HashSet<Account>(mAccountCache);
    removedAccounts.removeAll(currentAccounts); // populated with Accounts that were removed.
}