ITEDERDATA가 설정되고 있음에도 불구하고 NULL을 반환합니다
-
11-12-2019 - |
문제
계정 및 자격 증명을 저장하기 위해 AccountManager 를 사용하는 Android 앱에서 작업하고 있습니다.한 가지 문제가있는 문제는 문자열 값을 AccountManager의 addAccountExplicity 데이터 번들에 전달하더라도
번들이 not 이 아니며 은 계정을 추가하기 전에 값을 포함하는지 확인합니다.대부분의 시간은 사례이지만,이 값을 쿼리 할 때 나는 null을 얻습니다.
방금 계정을 삭제하고 다시 추가 한 후에 NULL 반환 값이 더 일반적입니다.
onAccountSupDatelistener 구현의 메소드에서 내 쿼리를하고 있으므로 계정을 추가하고 잘 알아야합니다.
도움말 감사합니다
인증 기작
.
// 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);
다른 스레드
.AccountManager am = AccountManager.get(mContext);
final string value2 = am.getUserData(mAccount, k2);
if (TextUtils.isEmpty(value2)) {
Log.d("WTF", "value is empty");
}
해결책
Honeycomb Plus에서 한 가지 버그를 알고 있으며 문제를 일으킬 수 있습니다.등록되기 전에 계정의 GetUserData를 사용하려고하면 모든 후속 getUserData 호출이 null를 반환합니다. 코드를 보면
.AccountManager에는 SQLite 데이터베이스가 지원하는 메모리 내 캐시가 있습니다.GetUserData를 호출하면 인 메모리 캐시 userData가 등록되어 있지 않아도됩니다.등록되지 않은 경우 UserData로 해석하십시오.계정을 등록하면 데이터베이스 만 채취하고 메모리 내 저장소가 무효화되지 않습니다.
이 문제를 일으킬 수 있습니다.
해결 방법은 AddAccountExplicity를 호출하기 전에 계정을 제거하는 것입니다.
ya이 문제는 짜증나고 AccountManger IMO의 거대한 버그이며 제 3자가 에센스 도스에 앱을 제공합니다.
다른 팁
Android 4가있는 HTC 장치를 사용하고 있습니까?내 동기화 응용 프로그램 사용자 에게이 문제에 대한 많은 보고서가 있습니다. 모두 은 SDK 레벨 15가있는 HTC 장치를 사용했습니다.
은 나에게 htc 버그처럼 보입니다.
여러 사용자가 재부팅 한 후에 문제가 사라지는 것을보고했습니다.
update : 한편 올바른 해결 방법을 찾았습니다. https://stackoverflow.com/a/29776224/1558654
I had a similar issue, but my problem turned out to be attempting to store a long userData value instead of a String. Converting my long to a string for storage, and parsing it into a long again when pulling it out did the trick for me.