문제

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!

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top