Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top