AccountManager without a SyncAdapter?
Asked Answered
W

4

8

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)
Wyman answered 21/6, 2010 at 13:56 Comment(0)
S
7

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

Scaffolding answered 17/8, 2010 at 11:34 Comment(0)
C
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

Catalan answered 21/10, 2010 at 16:10 Comment(0)
B
1

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.

Bernt answered 10/1, 2011 at 3:0 Comment(0)
M
0

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...

Masakomasan answered 28/6, 2010 at 17:33 Comment(1)
HI, there is a SyncAdapter, a named ContactsSyncAdapterService classDried

© 2022 - 2024 — McMap. All rights reserved.