Hi I am implementing an account sync adapter and i am trying to make a preference screen in settings under Account and Sync for the user to be able to change the sync interval. what i want to know is how can i make the adapter sync at the specified time on the preference screen? does android provide a method for that? what i was thinking of doing was saving the time of the last successful sync and comparing the passed time since then with the period stored in preferences. is this the right way to do it or is there a cleaner solution to my problem?
2 Answers
What you can do is call the method addPeriodicSync(Account account, String authority, Bundle extras, long pollFrequency) Specifies that a sync should be requested with the specified the account, authority, and extras at the given frequency. I think it will solve your problem.

- 375
- 2
- 7
- 24
-
This is good but i cant use it because its a method added in api 8. i need something that will work on min sdk 7. – DArkO Apr 26 '11 at 11:11
-
1you can call requestSync(Account account, String authority, Bundle extras) Start an asynchronous sync operation. after a specified time. – shunty Apr 27 '11 at 02:15
For an example, see this commit where I added an option to change the sync interval in one of my apps. This commit then expanded on that by dynamically choosing how this is done, based on the api level of the os its currently running on, so it uses the built in method for 8+, and the alarm for <8.
The gist of it is that setting the interval on api <8 creates an alarm using the AlarmManager api with the specified interval that triggers a BroadcastReceiver to call requestSync.

- 1,666
- 1
- 10
- 14