Sum*_*att 11 android accountmanager android-authenticator android-account
当我在我的应用程序中使用test1@gmail.com登录时.它使用我的电子邮件成功生成帐户
现在我注销并使用不同的电子邮件登录,如test2@gmail.com,然后生成这样的帐户
我想知道哪种方式最好
1)删除第一个帐户并添加第二个帐户
2)如果可以更新,则用第二个帐户更新第一个帐户.
如果我删除并再次添加帐户使用addAccountExplicitly它需要一些时间来创建新帐户,所以我的下一个代码执行,帐户返回null.
是否可以使用帮助更新帐户,updateCredentials如果是,那么如何?
我到底做了什么?
创建包含帐户所需数据的捆绑包
检查帐户是否已存在本地插入的bundle params"global_user_id",如果它已经存在,那么我必须更新用作登录的EMAIL(参见上图).
目前我正在执行,删除旧帐户和添加新帐户,但下一行是SyncAdapter配置,需要帐户.因为添加帐户需要一些时间才能获得NULL.
有没有其他解决方案来更新电子邮件ID?
我得到了这个问题的解决方案.
问题:删除/添加帐户仍为空account对象
首先我删除了使用的帐户removeAccount(),然后尝试addAccountExplicitly但removeAccount()服用时间执行后台线程同时addAccountExplicitly叫,做进一步的处理.
所以我改变了我的流程,因为我使用removeAccount了AccountManager类的方法并在该处理程序中执行整个过程,所以我在回调区域内编写代码.
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
mAccountManager.removeAccount(accounts[0], LoginActivity.this, new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> future) {
// Creating the account on the device and setting the auth token we got
// (Not setting the auth token will cause another call to the server to authenticate the user)
mAccountManager.addAccountExplicitly(account, accountPassword, intent.getBundleExtra(AccountManager.KEY_USERDATA));
mAccountManager.setAuthToken(account, authTokenType, authToken);
/**
* Setting for Sync Adapter
* Syncing Configuration
*/
SyncAdapter.configSyncAdapter(mContext);
}
}, null);
} else {
mAccountManager.removeAccount(accounts[0], new AccountManagerCallback<Boolean>() {
@Override
public void run(AccountManagerFuture<Boolean> future) {
// Creating the account on the device and setting the auth token we got
// (Not setting the auth token will cause another call to the server to authenticate the user)
mAccountManager.addAccountExplicitly(account, accountPassword, intent.getBundleExtra(AccountManager.KEY_USERDATA));
mAccountManager.setAuthToken(account, authTokenType, authToken);
/**
* Setting for Sync Adapter
* Syncing Configuration
*/
SyncAdapter.configSyncAdapter(mContext);
}
}, null);
}
Run Code Online (Sandbox Code Playgroud)
我找到了名为renameAccount()的方法,但它需要最小的sdk版本21.根据文档:
重命名指定的帐户.这相当于删除现有帐户并使用旧帐户的用户数据添加新的重命名帐户.
从主线程调用此方法是安全的.
谢谢.
| 归档时间: |
|
| 查看次数: |
875 次 |
| 最近记录: |