11

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?

Community
  • 1
  • 1
karthik
  • 133
  • 1
  • 1
  • 7

2 Answers2

5

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

Sean
  • 7,562
  • 10
  • 27
  • 29
4

I think what would be optimal for your problem would be to use GCM Push for pushing unsynchronised server data to your android client. For syncing your client's SQL Data, you would know what hasn't been updated to the Server and whenever the device is net-connected push this data to the Server. A higher layer of communication between Client and Server can implement the decision of what is unsynchronised. The above assumes you have your own server with which your client would be communicating.

Considering you do not own the Server- your strategy of writing a sync adapter seems good. This link shall help you know the intricacies of Sync Adapter

mesh
  • 849
  • 9
  • 16
  • I forgot to mention that I do not own the Web Service, I am accessing an API which provides me JSON Data. I'm not quite sure the GCM part would work in this scenario? – karthik Nov 20 '14 at 07:14
  • Oh, ok in that case i think you should write your own SyncAdapter to do it efficiently. No Push would work as you say it's not your own server. – mesh Nov 20 '14 at 08:39
  • Thank you very much for linking me to that very informative post. Solves my issue. – karthik Nov 20 '14 at 13:30