I want to clear the application\'s data when a user manually removes an account from the Accounts & sync
section in the settings app.
I have my own impl
I've been pondering on the same problem and here's the "solution" I decided upon. It's not what I'd call the "correct" solution but it's the best I believe you can manage with the current API.
In my implementation of the AbstractAccountAuthenticator
class, I've overriden the getAccountRemovalAllowed
function as follows:
@Override
public Bundle getAccountRemovalAllowed(
AccountAuthenticatorResponse response, Account account)
throws NetworkErrorException {
Bundle result = super.getAccountRemovalAllowed(response, account);
if (result != null && result.containsKey(AccountManager.KEY_BOOLEAN_RESULT)
&& !result.containsKey(AccountManager.KEY_INTENT)) {
final boolean removalAllowed = result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT);
if (removalAllowed) {
// Do my removal stuff here
}
}
return result;
}
There is a tiny chance that removal could fail AFTER you return from getAccountRemovalAllowed
but it's negligible (IMHO).
As MisterSquonk suggested there is an Intent that you could listen for (ACCOUNTS_CHANGED_INTENT
) but, unfortunately, it's broadcast when an account changes, and not just when an account is deleted.
I don't understand why this isn't part of the SDK but maybe we've both missed something obvious! For now, I'm sticking with this approach as I need to delete some database tables of my own on account deletion.
I hope this helps.