Question

I'm using a syncadapter in my application. I need it to trigger an event every day, at 6 AM. Is that possible?

Is there a way to trigger a syncadapter event every day at a given time?

Thanks!

Was it helpful?

Solution

This may help: ContentResolver.addPeriodicSync()

This, too: Transferring Data Using Sync Adapters

Or, you can always trigger a sync yourself: ContentResolver.requestSync()

However, I advise against doing a requestSync() unless you're dead certain that you need to sync with a server every day at 6 AM regardless of what's happened with the data. The point of a sync adapter is that the system helps you keep your device up-to-date without wasting battery. If you keep turning WiFi or data access off and on to do syncs, you're using far more battery than if you let the sync adapter framework schedule everything for you.

OTHER TIPS

I feel like the accepted answer didn't really answer the question. This is what I found in the docs:

"Notice that addPeriodicSync() doesn't run the sync adapter at a particular time of day. To run your sync adapter at roughly the same time every day, use a repeating alarm as a trigger. Repeating alarms are described in more detail in the reference documentation for AlarmManager."

http://developer.android.com/training/sync-adapters/running-sync-adapter.html#RunPeriodic

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top