如何启用不同步每隔几秒同步 [英] How to enable sync without syncing every few seconds

查看:291
本文介绍了如何启用不同步每隔几秒同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用了谷歌的Andr​​oid开发者文档( http://developer.android.com/training/同步适配器)创建一个同步系统。

I have used Google's Android developer documentation (http://developer.android.com/training/sync-adapters) to create a syncing system.

我的应用程序现在已经在账户在Android设置的条目。当我点击该条目,我看到了同步适配器我已经配置。一切看起来都OK,只是没有选中该复选框,它说同步熄灭。

My app now has an entry in Android Settings under Accounts. When I tap this entry, I see the sync adaptor I have configured. Everything looks ok except that the box is unchecked and it says "Sync is OFF".

我用Google搜索和Stackoverflowed并似乎有一种方式来启用同步,如下解释: http://stackoverflow.com /一/十二万七千四百三十四分之五百二十七万九千一百九十一。在这个环节中回答说叫 ContentResolver.setSyncAutomatically(帐户,权威,真实)

I have Googled and Stackoverflowed and there seems to be one way to enable sync, as explained here: http://stackoverflow.com/a/5279191/127434. The answer at that link says to call ContentResolver.setSyncAutomatically(account, authority, true).

不过,谷歌的文档(的http://developer.android.com/training/sync-adapters/running-sync-adapter.html#RunByNetwork)说:

However, Google's docs (http://developer.android.com/training/sync-adapters/running-sync-adapter.html#RunByNetwork) say:

在网络连接可用,Android系统发出一个   每隔几秒钟的消息,以保持设备的TCP / IP连接开放。   该消息还去每个应用程序的ContentResolver的。通过调用   setSyncAutomatically(),您可以运行同步适配器每当   ContentResolver的接收消息

When a network connection is available, the Android system sends out a message every few seconds to keep the device's TCP/IP connection open. This message also goes to the ContentResolver of each app. By calling setSyncAutomatically(), you can run the sync adapter whenever the ContentResolver receives the message.

但我不希望每隔几秒同步。 (我想使用 ContentResolver.addPeriodicSync 来安排同步几次一小时。)

But I don't want to sync every few seconds. (I'd like to use ContentResolver.addPeriodicSync to schedule a sync a few times an hour.)

那么,如何才能启用同步我的适配器,而无需同步,它每隔几秒钟?

So how can I enable syncing for my adaptor without having it sync every few seconds?

推荐答案

您应该添加         ContentResolver.setMasterSyncAutomatically(真正的);您的code。没有这个的setSyncAutomatically将被忽略。

You should add ContentResolver.setMasterSyncAutomatically(true); to your code. Without this the setSyncAutomatically will be ignored.

阅读文档[这里](<一href="http://developer.android.com/reference/android/content/ContentResolver.html#setMasterSyncAutomatically%28boolean%29" rel="nofollow">http://developer.android.com/reference/android/content/ContentResolver.html#setMasterSyncAutomatically(boolean))

这篇关于如何启用不同步每隔几秒同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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