Change your Android accountโ€™s sync interval in settings

Hi I am implementing an account synchronization adapter, and I am trying to make the settings screen in the settings under the account and synchronization so that the user can change the synchronization interval. what I want to know how can I do adapter synchronization at a specified time on the preferences screen? Does android make a method for this? what I was thinking about is saving the time of the last successful synchronization and comparing the elapsed time since then with the period saved in the settings. Is this the right way to do this or is there a cleaner solution to my problem?

+4
source share
2 answers

What you can do is call the addPeriodicSync method (account, String credentials, optional components, long pollFrequency) Specifies that synchronization should be requested with the specified credential, credentials, and additional data at a given frequency. I think this will solve your problem.

+3
source

For an example, see this commit , where I added a parameter to change the synchronization interval in one of my applications. Then this commit expanded it, dynamically choosing how to do it, based on the api level of the current os start, so it uses the built-in method for 8+ and the alarm for <8.

Its essence is that setting the interval on api <8 creates an alarm using the AlarmManager attribute api with the specified interval, which launches BroadcastReceiver to call requestSync.

+1
source

All Articles