我知道AccountManager
的addOnAccountsUpdatedListener()
可用于获取有关帐户列表更改的通知。如果发生这种事件,框架将调用提供的OnAccountsUpdateListener
的onAccountsUpdated()
方法。但该方法的参数仅包含帐户列表。我怎么知道用户删除了哪个帐户?提前谢谢!
答案 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.
}