Android 计划的同步适配器每30秒运行一次
我在应用程序中使用同步适配器定期从服务器同步更改。无论我在pollFrequency中输入什么值,同步都会每30秒运行一次 我在论坛上查看并尝试了回复中建议的更改,当我在ContentResolver上引发notifyChange时,我将“false”作为SynctonNetwork参数传递 在再次详细地进行培训时,我偶然发现了这种差异 在谷歌开发者网站->培训部分 我看到addPeriodicSync->pollFrequency参数以毫秒为单位传递Android 计划的同步适配器每30秒运行一次,android,android-contentresolver,android-syncadapter,Android,Android Contentresolver,Android Syncadapter,我在应用程序中使用同步适配器定期从服务器同步更改。无论我在pollFrequency中输入什么值,同步都会每30秒运行一次 我在论坛上查看并尝试了回复中建议的更改,当我在ContentResolver上引发notifyChange时,我将“false”作为SynctonNetwork参数传递 在再次详细地进行培训时,我偶然发现了这种差异 在谷歌开发者网站->培训部分 我看到addPeriodicSync->pollFrequency参数以毫秒为单位传递 public class MainActi
public class MainActivity extends FragmentActivity {
...
// Constants
// Content provider authority
public static final String AUTHORITY = "com.example.android.datasync.provider";
// Account
public static final String ACCOUNT = "default_account";
// Sync interval constants
public static final long MILLISECONDS_PER_SECOND = 1000L;
public static final long SECONDS_PER_MINUTE = 60L;
public static final long SYNC_INTERVAL_IN_MINUTES = 60L;
//This is the line I'm referring to
public static final long SYNC_INTERVAL = SYNC_INTERVAL_IN_MINUTES *
SECONDS_PER_MINUTE *
MILLISECONDS_PER_SECOND;
// Global variables
// A content resolver for accessing the provider
ContentResolver mResolver;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
// Get the content resolver for your app
mResolver = getContentResolver();
/*
* Turn on periodic syncing
*/
ContentResolver.addPeriodicSync(
ACCOUNT,
AUTHORITY,
null,
SYNC_INTERVAL);
...
}
...
}
在API参考上,轮询频率以秒为单位。预期的单位频率是多少,毫秒还是秒?
非常感谢您的帮助。您应该添加
ContentResolver.setMasterSyncAutomatically(true)添加到您的代码。否则,将忽略自动设置同步
阅读文档。您的
同步间隔应以秒为单位,而不是以毫秒为单位
addPeriodicSync()文档说明:
轮询执行同步的频率,以秒为单位
请张贴您的实际代码。