views:

97

answers:

1

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 access.

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.

Please help.

Thanks.

+1  A: 

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.

Megha Joshi
Thanks Megha! I will check the sample project out(seems I'd have to download 2.2 for that). Plz validate my understanding: this is basically a class that is designed to make synchronization activity between two parties easy?I'll have to write all the network communication, XML parsing, data persistence logic and apply a layer of SyncAdapter to encapsulate all flows?
Samuh
Yes, that is correct.
Megha Joshi