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");
}