I am trying to implement an app to utilize a RESTful web service. I've studied several different examples and have coded a good working app that does successful pulls from the REST service. But now I need some direction. Here's some basic background (very simplified)...
Activity
, I call a managedQuery
to get a Cursor
back from the ContentProvider
for my ListView
.ContentProvider
returns back any local data, and calls an async "GetReferrers" to get the latest server list of referrers.ResponseHandler
to parse the JSON and insert it into the ContentProvider
.ContentProvider
upon a successful "get" from the server, then inserting the new/updated list to the database.Two questions I have are...
When I do a new GET, would it be common practice to delete all the existing records in the local ContentProvider
and insert the new list? Or would it be better (albeit more time consuming) to do checks for new/changed/deleted records to only add/change/delete, respectively?
I really don't have any idea where to start on doing an "add" from the client to utilize the "AddReferrer" REST method. I know how to add a new item locally to the ContentProvider
using ContentValues
with a getContentResolver().insert()
. But, where would I put the code to push that up to the server? Or would it be more common practice to skip adding to the local ContentProvider
, push it up to the server, then let the GET pull it back to the local ContentProvider
?
Hope that all makes sense. I'd appreciate any direction you can give. If anybody knows of a good two-way example like this, please share. All examples of REST client operations I've found so far are just doing "gets" from the server and not pushes back up.
When I had to do something like this once I could implement a REST method like getReferrersSince(timestamp)
, which gave me only the changes since my last sync. But if the service is not under your control I would also suggest the first option. Checking every entry for changes probably takes as long as deleting and re-inserting them all, but it's much more likely to be inconsistent.
btw: Daniele Teti is right. So it was actually something likeGET http://.../referrers?since=[timestamp]
Just to make sure: Did you watch Virgil Dobjanschi? He suggests inserting the items locally first and marking them as "pending" in an extra database column (eg. SYNC_STATUS
). Then have a service that uploads all pending items via REST in the background and marks them as "synced".
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