我用谷歌搜索了这个问题,但没有找到任何解决方案。
我已经创建了自己的自定义帐户。当我尝试使用以下代码以编程方式删除帐户时,该帐户不会被删除:
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/