如何启用不同步每隔几秒同步

编程入门 行业动态 更新时间:2024-10-25 00:26:43
本文介绍了如何启用不同步每隔几秒同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I have used Google's Android developer documentation (developer.android/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并似乎有一种方式来启用同步,如下解释: stackoverflow /一/十二万七千四百三十四分之五百二十七万九千一百九十一。在这个环节中回答说叫 ContentResolver.setSyncAutomatically(帐户,权威,真实)。

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

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

However, Google's docs (developer.android/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.

阅读文档[这里](developer.android/reference/android/content/ContentResolver.html#setMasterSyncAutomatically(boolean))

更多推荐

如何启用不同步每隔几秒同步

本文发布于:2023-10-26 19:08:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531086.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:每隔   几秒   不同步

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!