Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 285
Samuh Avatar asked Sep 08 '10 04:09

Samuh


People also ask

What is the use of sync adapter in android?

The sync adapter component in your app encapsulates the code for the tasks that transfer data between the device and a server. Based on the scheduling and triggers you provide in your app, the sync adapter framework runs the code in the sync adapter component.

What is the purpose of activity in Android?

An activity provides the window in which the app draws its UI. This window typically fills the screen, but may be smaller than the screen and float on top of other windows. Generally, one activity implements one screen in an app.

What is offline synchronization in android?

Offline sync allows end users to interact with a mobile app—viewing, adding, or modifying data—even when there's no network connection. Changes are stored in a local database. Once the device is back online, these changes are synced with the remote backend.


1 Answers

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.

like image 85
Megha Joshi - GoogleTV DevRel Avatar answered Nov 16 '22 00:11

Megha Joshi - GoogleTV DevRel