codepath / android_guides

Extensive Open-Source Guides for Android Developers
guides.codepath.com
MIT License
28.31k stars 6.35k forks source link

How can I combine AlarmManager with sync adapter? #358

Open zoezhou1999 opened 5 years ago

zoezhou1999 commented 5 years ago

I have read this in the document and guide, but I don't know how to use it. Can someone help me?

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. If you use the method setInexactRepeating() to set time-of-day triggers that have some variation, you should still randomize the start time to ensure that sync adapter runs from different devices are staggered.