根据订单的帐户设置呼叫SyncAdapter不会被调用 [英] SyncAdapter not being called depending on order of Account setup calls

查看:322
本文介绍了根据订单的帐户设置呼叫SyncAdapter不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经遇到一些稍微奇怪的行为与我的SyncAdapter。

I've come across some slightly odd behaviour with my SyncAdapter.

我第一次安装我的应用程序(亚行卸载后),它会启动并创建一个帐户。根据一些语句的顺序(见下文),我SyncAdapter的onPerformSync()将永远不会被调用;在帐户和同步我的账户显示图标正在同步旋转下去。如果我再取消同步旁边的复选框我的应用程序的帐户,然后再检查吧,我的onPerformSync()被立即调用。

The first time I install my app (after uninstalling with adb), it launches and creates an account. Depending on the ordering of some statements (see below), my SyncAdapter's onPerformSync() will never be called; my account under "Accounts and sync" shows the "sync in progress" icon spinning indefinitely. If I then uncheck the sync checkbox next to my app's account, and then recheck it, my onPerformSync() is called immediately.

这使我SyncAdapter永远不会被调用。 同步进行中图标旋转永远,除非我取消,然后重新检查同步复选框:

final Account account = new Account(mUsername, getString(R.string.ACCOUNT_TYPE));
mAccountManager.addAccountExplicitly(account, mPassword, null);
ContentResolver.setSyncAutomatically(account, getString(R.string.CONTENT_AUTHORITY), true);
ContentResolver.setIsSyncable(account, getString(R.string.CONTENT_AUTHORITY), 1);

用同样的语句此排序,一切完美的作品:

final Account account = new Account(mUsername, getString(R.string.ACCOUNT_TYPE));
ContentResolver.setSyncAutomatically(account, getString(R.string.CONTENT_AUTHORITY), true);
ContentResolver.setIsSyncable(account, getString(R.string.CONTENT_AUTHORITY), 1);
mAccountManager.addAccountExplicitly(account, mPassword, null);

我的猜测是,我把SyncManager到一些不一致的状态,由于它发射了一个同步请求,立即在帐户创建,和我改变了它的脚下其配置。但(几乎一致)的文件没有提到任何问题,调用这些函数,只要你喜欢。

My guess is I'm putting the SyncManager into some inconsistent state due to it firing off a sync request instantly on account creation, and I'm changing its config under its feet. But the (barely coherent) documentation doesn't mention any issues with calling these functions whenever you like.

顺便给别人带SyncAdapters挣扎,我发现 contentResolver.requestSync()将永远不会触发你的 SyncAdapter.onPerformSync(),除非你调用 ContentResolver.setIsSyncable(帐户的getString(R.string.CONTENT_AUTHORITY),1);

As an aside for others struggling with SyncAdapters, I found that contentResolver.requestSync() will never trigger your SyncAdapter.onPerformSync() unless you call ContentResolver.setIsSyncable(account, getString(R.string.CONTENT_AUTHORITY), 1);.

有人能解释这种现象?周围的账户和同步文档是有些不清楚,至少可以说。

Could someone explain this behaviour? The documentation surrounding Accounts and Syncing is somewhat unclear to say the least.

我收到的2.1模拟器这种行为,编译对2.1的SDK。

I'm getting this behaviour on the 2.1 Emulator, compiling against the 2.1 SDK.

推荐答案

我发现, contentResolver.requestSync()绝不会触发您SyncAdapter.onPerformSync(),除非你打电话 ContentResolver.setIsSyncable(帐户的getString(R.string.CONTENT_AUTHORITY),1);

I found that contentResolver.requestSync() will never trigger your SyncAdapter.onPerformSync() unless you call ContentResolver.setIsSyncable(account, getString(R.string.CONTENT_AUTHORITY), 1);.

有关我去使用SyncAdapter解决方案的详细说明,请参阅我的答案在这里:

For a detailed account of the solution I went with using SyncAdapter, see my answer here:

http://stackoverflow.com/a/12015967/988870

这篇关于根据订单的帐户设置呼叫SyncAdapter不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆