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)...
- Assume a basic REST service that has "GetReferrers" and "AddReferrer" methods.
- From the
Activity
, I call amanagedQuery
to get aCursor
back from theContentProvider
for myListView
. - The
ContentProvider
returns back any local data, and calls an async "GetReferrers" to get the latest server list of referrers. - I have a custom
ResponseHandler
to parse the JSON and insert it into theContentProvider
. - As of now, I am deleting all records in the local
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
usingContentValues
with agetContentResolver().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 localContentProvider
, push it up to the server, then let the GET pull it back to the localContentProvider
?
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.