2014-04-04 38 views

回答

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. 
} 
+1

我想到這個問題的解決方案,但我希望有另一種方式。謝謝! – WonderCsabo