AccountManager哪个帐户被删除
问题描述:
我知道AccountManager
的addOnAccountsUpdatedListener()
可以用来获取有关帐户列表更改的通知。如果发生这种事件,框架将调用所提供的OnAccountsUpdateListener
的onAccountsUpdated()
方法。但该方法的参数只包含帐户列表。我如何知道用户删除了哪个帐户?提前致谢!AccountManager哪个帐户被删除
答
取决于你想做什么,你可能会摆脱这样的:
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.
}
我想到这个问题的解决方案,但我希望有另一种方式。谢谢! – WonderCsabo