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?
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).
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?
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With