I know that the AccountManager's addOnAccountsUpdatedListener() can be used to get notified about the changes of the list of accounts. If that kind of event happens, the framework will call the supplied OnAccountsUpdateListener's onAccountsUpdated() method. But the argument of the method only contains the list of accounts. How can i know which account was removed by the user? Thanks in advance!

有帮助吗?

解决方案

Depending on what you’re trying to do, you might get away with this:

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.
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top