1
我知道AccountManager
的addOnAccountsUpdatedListener()
可以用來獲取有關帳戶列表更改的通知。如果發生這種事件,框架將調用所提供的OnAccountsUpdateListener
的onAccountsUpdated()
方法。但該方法的參數只包含帳戶列表。我如何知道用戶刪除了哪個帳戶?提前致謝!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