Question

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!

Was it helpful?

Solution

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.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top