的AccountManager getUserData尽管它被设置返回null [英] AccountManager getUserData returning null despite it being set

查看:1478
本文介绍了的AccountManager getUserData尽管它被设置返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个Android应用程序,使用的AccountManager 存储帐户与证书。有一个问题我一直有是,即使我通过在一堆字符串值到的AccountManager的 addAccountExplicitly 的数据包。

我已经检查,以确保该包是不为空,它的包含添加帐户之前的值。而大部分时间是这样的话,但每过一段时间,我得到空当我查询这些值。

空返回值后,我刚刚删除的帐户,并重新添加它更常见。

我在做我的查询里面的 onAccountsUpdated 的方法的 OnAccountsUpdateListener 的实施,使该帐户应添加和好走,对吧?

感谢您的帮助

AuthenticatorActivity

  //在AuthenticatorActivity
捆绑用户数据=新包();
userData.put(K1,V1);
userData.put(K2,v2)的;
userData.put(K3,V3);
userData.put(K4,V4);
userData.put(K1,V1);

帐户A =新的帐户(ACC名,com.account.type);
的AccountManager AM = AccountManager.get(本);

OnAccountsUpdateListener监听器=新OnAccountsUpdateListener(){

        @覆盖
        onAccountsUpdated(帐户[]帐户)公共无效{
            账户矿= findAccount(帐户,帐户); //匹配的帐户名
            notifySignedIn(矿); //告诉您在签署世界
            am.removeOnAccountsUpdatedListener(本);
        }
    };

am.addOnAccountsUpdatedListener(监听器,处理器,假);
am.addAccountExplicitly(一,themostsecurepwintheworld,用户数据);
 

一些其他线程

 的AccountManager AM = AccountManager.get(mContext);
最终的字符串值2 = am.getUserData(mAccount,K2);

如果(TextUtils.isEmpty(值2)){
    Log.d(跆拳道,值是空);
}
 

解决方案

我知道一个bug被纠正的蜂窝加,可能会导致您的问题。如果你尝试的帐户,以getUserData在注册前所有后续getUserData调用将返回null。

如果你看一下code。的AccountManager有由SQLite数据库支持的内存缓存。调用getUserData填充内存中缓存用户数据,即使未注册。如果不注册就跨$ P $点,由于没有任何用户数据。注册一个帐户只填充数据库和内存存储不会失效。

这可能会导致您的问题。

解决方法是调用addAccountExplicitly之前删除该帐户。

雅这个问题很烂,是AccountManger IMO一个巨大的错误,并允许第三方本质DOS的应用程序。

I'm working on an Android app that uses the AccountManager to store accounts & credentials. One problem I've been having is that even though I pass in a bunch of String values to the AccountManager's addAccountExplicitly data bundle.

I have checked to make sure that the bundle is not empty and that it contains the values before adding the account. And most of the time this is the case, but every once in a while I get null when I query these values.

The null return values are more common after I've just deleted the account and re-added it.

I'm doing my query inside the onAccountsUpdated method of an OnAccountsUpdateListener implementation, so the account should be added and good to go, right?

Thanks for any help

AuthenticatorActivity

// in the AuthenticatorActivity
Bundle userData = new Bundle();
userData.put (k1, v1);
userData.put (k2, v2);
userData.put (k3, v3);
userData.put (k4, v4);
userData.put (k1, v1);

Account a = new Account ("acc name", "com.account.type");
AccountManager am = AccountManager.get(this);

OnAccountsUpdateListener listener = new OnAccountsUpdateListener() {

        @Override
        public void onAccountsUpdated(Account[] accounts) {
            Account mine = findAccount(accounts, account); // match account name
            notifySignedIn(mine); // tell the world you're signed in
            am.removeOnAccountsUpdatedListener(this);
        }
    };

am.addOnAccountsUpdatedListener(listener, handler, false);
am.addAccountExplicitly(a, "themostsecurepwintheworld", userData);

Some other thread

AccountManager am = AccountManager.get(mContext);
final string value2 = am.getUserData(mAccount, k2);

if (TextUtils.isEmpty(value2)) {
    Log.d("WTF", "value is empty");
}

解决方案

I am aware of one bug in Honeycomb plus that can cause your issue. If you try to getUserData of the account before it is registered all subsequent getUserData calls will return null.

If you look at the code. AccountManager has an in-memory cache that is backed by a sqlite database. Calling getUserData populates the in-memory cache userdata, even if it is not registered. If it is not registered it interprets that as no userdata. Registering an account only populates the database and does not invalidate the in-memory store.

This may be causing your issue.

The workaround is to remove the account before calling addAccountExplicitly.

Ya this issue sucks and is a HUGE bug in AccountManger IMO and allows third parties to essence DOS your app.

这篇关于的AccountManager getUserData尽管它被设置返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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