清算帐户去除数据 [英] Clearing data on account removal

查看:228
本文介绍了清算帐户去除数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要清除应用程序的数据,当用户手动删除从帐户与帐户;同步在设置应用程序的部分。

I want to clear the application's data when a user manually removes an account from the Accounts & sync section in the settings app.

我有我自己的实现 AbstractAccountAuthenticator ,但没有办法在删除帐户进程挂钩。任何提示?

I have my own implementation of AbstractAccountAuthenticator but there is no method to hook in the remove account process. Any hints?

推荐答案

我一直在琢磨同样的问题,这里的解决方案我决定的。这不是我称之为正确的解决方案,但它是最好的,我相信你可以使用目前的API管理。

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.

在我实施 AbstractAccountAuthenticator 类,我已经重写了 getAccountRemovalAllowed 函数如下:

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;
}

有一个微小的机会,去除可能失败后您从 getAccountRemovalAllowed 返回,但它是可以忽略不计(恕我直言)。

There is a tiny chance that removal could fail AFTER you return from getAccountRemovalAllowed but it's negligible (IMHO).

由于MisterSquonk建议有,你可以听( ACCOUNTS_CHANGED_INTENT ),但不幸的是,广播的意图时,帐户的修改的,并不只是当一个帐户的删除的。

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.

我不明白为什么这不是SDK的一部分,但也许我们俩都错过了一些明显的!现在,我用这个办法坚持,因为我需要删除的帐户删除一些我自己的数据库表。

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.

我希望这有助于。

这篇关于清算帐户去除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆