我如何从我自己的 Authenticator 的 AccountManager 注销?
How do I logout from AccountManager for my own Authenticator?
我正在关注 this question 的回答。
但是我得到这个错误:
java.lang.NoSuchMethodError: No virtual method removeAccount(Landroid/accounts/Account;Landroid/app/Activity;Landroid/accounts/AccountManagerCallback;Landroid/os/Handler;)Landroid/accounts/AccountManagerFuture; in class Landroid/accounts/AccountManager; or its super classes (declaration of 'android.accounts.AccountManager' appears in /system/framework/framework.jar).
如何正确退出?
public void logOut() {
final Account accounts[] = mAccountManager.getAccounts();
if (accounts.length > 0) {
mAccountManager.removeAccount(accounts[0], (Activity) context, new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> future) {
try {
Bundle bnd = future.getResult();
Log.d(TAG, String.valueOf(bnd));
} catch (Exception e) {
e.printStackTrace();
}
}
}, null);
}
}
我的解决方案如下。虽然它已被弃用,但它确实有效。如果您知道更好的解决方案,我将不胜感激。
mAccountManager.removeAccount(account, new AccountManagerCallback<Boolean>() {
@Override
public void run(AccountManagerFuture<Boolean> future) {
try {
if (future.getResult()) {
// do something
}
} catch (Exception e) {
e.printStackTrace();
}
}
}, null);
我正在关注 this question 的回答。
但是我得到这个错误:
java.lang.NoSuchMethodError: No virtual method removeAccount(Landroid/accounts/Account;Landroid/app/Activity;Landroid/accounts/AccountManagerCallback;Landroid/os/Handler;)Landroid/accounts/AccountManagerFuture; in class Landroid/accounts/AccountManager; or its super classes (declaration of 'android.accounts.AccountManager' appears in /system/framework/framework.jar).
如何正确退出?
public void logOut() {
final Account accounts[] = mAccountManager.getAccounts();
if (accounts.length > 0) {
mAccountManager.removeAccount(accounts[0], (Activity) context, new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> future) {
try {
Bundle bnd = future.getResult();
Log.d(TAG, String.valueOf(bnd));
} catch (Exception e) {
e.printStackTrace();
}
}
}, null);
}
}
我的解决方案如下。虽然它已被弃用,但它确实有效。如果您知道更好的解决方案,我将不胜感激。
mAccountManager.removeAccount(account, new AccountManagerCallback<Boolean>() {
@Override
public void run(AccountManagerFuture<Boolean> future) {
try {
if (future.getResult()) {
// do something
}
} catch (Exception e) {
e.printStackTrace();
}
}
}, null);