android - 无法删除我自己的自定义帐户

标签 android accountmanager

我用谷歌搜索了这个问题,但没有找到任何解决方案。

我已经创建了自己的自定义帐户。当我尝试使用以下代码以编程方式删除帐户时,该帐户不会被删除:

Account systemAccount = new Account(mainAccount.getDisplayName(), 
                                    getResources().getString(R.string.account_type));
AccountManager.get(Accounts.this).removeAccount(systemAccount, null, null);

甚至,当我尝试从“设置”中删除帐户时,也没有任何反应。 仅当我卸载应用程序时,该帐户才会被删除。

我该怎么办?

最佳答案

您没有使用 Future作为参数传递给 AccountManagerCallback<Boolean>#run方法。

您应该将回调作为第二个参数提供给: public AccountManagerFuture<Boolean> removeAccount (Account account, AccountManagerCallback<Boolean> callback, Handler handler)

myAccountManager.removeAccount(myAccount, new AccountManagerCallback<Boolean>() {
    @Override
    public void run(AccountManagerFuture<Boolean> future) {
        // This is the line that actually starts the call to remove the account.
        boolean wasAccountDeleted = future.getResult();
    }
}, null);

你应该小心你如何称呼future.getResult() .不应在主 UI 线程上调用它。为简洁起见,此示例未提供该机制。

关于android - 无法删除我自己的自定义帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15358271/

相关文章:

java - 应用程序因 if 语句而崩溃

java - 注册期间用于密码检查的简单正则表达式是什么?

android - getAuthToken y Android 未调用任何回调

java - Android Studio TextViews onClick 都执行相同的操作,我该如何解决?

android - 如何在警告对话框中使用多个 EditBox

android - 检查 View 外的点击

android - 通过账户管理器添加账户

android - 谷歌 AccountManager Android

android - 无法从具有相同身份验证器的不同应用程序添加新的自定义帐户

android - AccountAuthenticatorActivity 上的 getSupportFragmentManager