Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 968
karthik Avatar asked Nov 20 '14 05:11

karthik


2 Answers

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

like image 131
Sean Avatar answered Oct 28 '22 02:10

Sean


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

like image 32
mesh Avatar answered Oct 28 '22 04:10

mesh