AccountManager 没有 SyncAdapter?

发布于 2024-09-06 21:52:49 字数 1357 浏览 7 评论 0原文

我正在尝试使用 AccountManager 来存储帐户信息并实现了身份验证器,但我不断收到如下所示的异常,导致手机崩溃。与示例代码相比,这似乎是因为我没有(或特别想要)SyncAdapter 和相关服务。在不添加 SyncAdapter 的情况下使用 AccountManager 是否有技巧?

问候

菲尔

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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

寒尘 2024-09-13 21:52:49

我有同样的问题。我实现了一个 AccountAuthenticator,它直接在 addAccount 方法中添加帐户,因为在我的情况下不需要用户输入。

创建帐户后,我收到异常并想要查看“帐户和同步”首选项屏幕。这不是由创建引起的,因为它与“开发工具> AccountsTester”一起使用。

编辑:
我想这就是解释,我会尝试一下。

“[...] 崩溃是由 Android 代码中未记录的假设引起的
处理帐户和同步。它们非常密切相关。它
事实证明,“帐户和同步”设置插件获取后
系统上的帐户,使用内容服务进行扫描
系统上实现意图的服务
“android.content.SyncAdapter”。

由于我们的代码没有实现这一点,因此搜索空手而归
由于代码假设这永远不会发生,BAM,空指针
异常和崩溃。 [...]”来自: http://osdir.com/ml /Android-Developers/2009-11/msg05288.html

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

八巷 2024-09-13 21:52:49

最后我需要添加一个 SyncAdapter 和一个 ContentProvider。只是最简单的存根实现,但它似乎可以完成工作。我还认为我发现2.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

影子是时光的心 2024-09-13 21:52:49

这是一个已知问题:http://code.google.com/p/ android/issues/detail?id=5009

出现NPE是因为没有找到对应的同步适配器。

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.

躲猫猫 2024-09-13 21:52:49

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

尽管有标题,但我在此处的代码(独立项目)中没有看到任何 SyncAdapter,这与 Google 的不同参考实现。

我认为你的异常是由其他原因引起的......

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文