开发者

Android SyncAdapter use case

What we are doing currently?

We have some structured, textual data on a server which is exposed using web services(RESTful). My application polls this server regularly(AlarmManagerService) to fetch the data and save it on local database(sqlite). Also, a user is authenticated and authorized beforehand for acce开发者_开发百科ss.

Questions:

  1. There is a SyncAdapter/AccountManager class in the SDK and I was wondering if it can be of any use in my application to achieve the syncing mentioned above?

  2. If yes, what sort of infrastructure is needed at back end to support a sync set up using this adapter? Links to articles etc. that give details of using this adapter and other info is appreciated.


Yes SyncAdapter/AccountManager is useful for your usecase. The Authenticator ( which calls AccountManager behind the scene) can handle authentication for your app. The SyncAdapter can handle periodic syncs from server to local datastore. You wont have to implement it yourself using AlarmManager. For samplecode on using SampleSycnAdapter/Authenticator please see the SampleSyncAdapter in android devguide.

Your backend REST server will work with the SyncAdapter just fine, without much changes. The only differences would be in your client, like for example instead of calling server's fetch data methods in AlarmManager, you would instead call them in onPerformSync() of your class which extends SyncAdapter. The sample code mentioned above will make it more clear.Hope this helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜