开发者

Where is the best place to schedule AlarmManager to do a periodic background data sync?

My Android application will be periodically polling a server to check for data. I want this polling to happen regardless of user interaction with the application, similar (in concept) to how the Gmail and Google Reader apps sync data in the background. Once the app is installed, these periodic syncs should begin happening. I do not think that scheduling the alarm from inside an Activity is the way to go, because I do not want to wait for the user to open my application.

What is the best practice in this case for placing the call to AlarmManager.setInexactRepeating?

Some possibilities I could think of are:

  • Extend Application and开发者_StackOverflow中文版 do it in onCreate
  • Do the scheduling from within a Service that is set to android:enabled=true within the manifest.
  • Listen for some particular broadcast message(s), and schedule from within a receiver


Create a on boot receiver and use it to start a service that schedules the alarm. Check out this link: http://www.thetekblog.com/?p=77


"Do the scheduling from within a Service that is set to android:enabled=true within the manifest."

A service is enabled by default - but that doesn't mean anything would start it automatically. The only reason a service would be disabled in configuration is if you have some code somewhere that enables it programmatically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜