Desiging an Android App with Offline Sync. Should I use SyncAdapter?

karthik picture karthik · Nov 20, 2014 · Viewed 11.2k times · Source

I'm trying to make an Android To-Do client for a web service, with offline caching and sync.

The web service returns data in JSON format about To-Do tasks on the server when you send it a post message. To add a To-Do on the server, you need to send a JSON POST to the server with the task details, upon which it will return you a task UUID.

I want to implement some type of synchronization so that the tasks I add when I am offline are sent to the server, and data from the server is synchronized to the app (2-way Sync) when Internet is available.

For now, I have written a basic content provider based To-Do app which does not talk to the server. My question is what would be the best way to go about implementing such a functionality?

Planning to Try

I figure that I need to fetch JSON from the server, push it into a local SQLite DB, perform comparisons and find unsynced items and push them to the server. I think I can do this by adding Asynchronous queries in my ContentProvider (Not sure if this is the best way).

Que:

Should I write my own implementation of the same or can a SyncAdapter do all of this magic? Are there any other design parameters that I should be considering?

Answer

Sean picture Sean · Nov 20, 2014

For a library to plug into your SyncAdapter and a demo app that demonstrates 2-way sync of Google Task API to local Android SQLite db - checkout this github repo:

https://github.com/sschendel/SyncManagerAndroid-DemoGoogleTasks