AccountManager without a SyncAdapter?

爷,独闯天下 提交于 2019-11-28 00:21:15

问题


I'm trying to use AccountManager to store account information and have implemented an authenticator, but I keep getting exceptions like the below that crash the phone. Comparing with sample code this seems to be because I don't have (or particularly want) a SyncAdapter and associated service. Is there a trick to using AccountManager without adding a SyncAdapter?

Regards

Phil

I/AuthenticatorActivity( 8526): onAuthenticationResult(true)
I/AuthenticatorActivity( 8526): finishLogin()
W/dalvikvm( 8108): threadid=13: thread exiting with uncaught exception (group=0x
4001b170)
E/AndroidRuntime( 8108): Uncaught handler: thread android.server.ServerThread ex
iting due to uncaught exception
E/AndroidRuntime( 8108): *** EXCEPTION IN SYSTEM PROCESS.  System will crash.
E/AndroidRuntime( 8108): java.lang.NullPointerException
E/AndroidRuntime( 8108):        at com.android.settings.ManageAccountsSettings.o
nSyncStateUpdated(ManageAccountsSettings.java:187)
E/AndroidRuntime( 8108):        at com.android.settings.ManageAccountsSettings.o
nAccountsUpdated(ManageAccountsSettings.java:244)
E/AndroidRuntime( 8108):        at android.accounts.AccountManager$10.run(Accoun
tManager.java:826)
E/AndroidRuntime( 8108):        at android.os.Handler.handleCallback(Handler.jav
a:587)
E/AndroidRuntime( 8108):        at android.os.Handler.dispatchMessage(Handler.ja
va:92)
E/AndroidRuntime( 8108):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 8108):        at com.android.server.ServerThread.run(SystemSer
ver.java:435)

回答1:


I have the same problem. I implemented a AccountAuthenticator, that adds the Account directly in the addAccount-method, because I don't need user input in my case.

I get the Exception after I created the Account and want to view the "Accounts & sync" preference screen. It isn't cause by the creation, because it works with the "Dev Tools > AccountsTester".

edit: I think this is the explanation, I will try it.

"[...] The crash is caused by an undocumented assumption in the Android code that handles accounts and sync. They are very closely related. It turns out that the "Accounts and Sync" settings plugin after getting the accounts on the system, uses the content service to scan for services on the system that implement the intent "android.content.SyncAdapter".

Since our code doesn't implement this, the search came up empty handed and since the code assumed this would never happen, BAM, null pointer exception and crash. [...]" from: http://osdir.com/ml/Android-Developers/2009-11/msg05288.html




回答2:


In the end I needed to add a SyncAdapter and a ContentProvider. Just the barest stub implementations, but it seemed to do the job. I also think I found that the problem doesn't occur on 2.2




回答3:


It's a known issue: http://code.google.com/p/android/issues/detail?id=5009

The NPE occurs because no corresponding sync adapter is found.




回答4:


http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/

Despite the title, I don't see any SyncAdapter in the code here (the standalone project), unlike Google's reference implementation.

I think your exception is caused by something else...



来源:https://stackoverflow.com/questions/3085242/accountmanager-without-a-syncadapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!