I know that this question has been asked too many times, but I think the issues I'm trying to target are a little bit different, maybe more complicated.
I am going to develop an application that uses a RESTful Web Service and needs to have the following requirements:
the app should show some books, their authors and their editors in lists and in detail
the app should also allow searching for a book
books, authors and editors are fetched from a RESTful web service
every entity has to be cached so that when I open an Activity I see the old data first (if any), while the new one updates from the network.
every time an entity is updating, the interested parties should be notified (
ContentObserver
? A regularListener
implementation?)if a call is already executing (say to
api/books/1337
or toapi/editors
) the caller should be notified that it is loading data and should be given the old one (if it exists), as if it was the original caller.some data (only books and authors) should be updated every N minutes (decided by the user) and the observers should be notified (
SyncAdapter
?)
Questions:
After watching and studying all of the components proposed by Virgil Dobjanschi at Google I/O 2010 here are my doubts:
How can I transparently handle the "entity-is-updating" concept for any caller? Should I use
ContentObserver
on aContentProvider
I will have to implement?If I use a
ContentObserver
I can easily set a status-flag for the single entity (as suggested by Dobjanschi), for exampleUPDATING
,INSERTING
, and so on. But how should I handle list? Say I want a list of books, where should I put the status flag? Should I put it in a status table for lists only? If so, I should observe twoCursor
s, one for the status and one for the actual list (i.e., the table/Content URI). And what if the entity I'm asking for does not exists (yet) or the REST call returns a404
? How do I handle the callback?If I put all of my REST methods in a
**SyncAdapter**
, can I "force" theSyncAdapter
to update an entity/entity list from the network (and therefore put it into the proper table)? This way, the status flag would be useful.Can the
SyncAdapter
work on multiple entities (actually, entity lists, as I want to update books and editors every now and then), since it only has aperformSync
method?If my
SyncAdapter
implementation has been disabled by the user in the device settings it won't update anything (and that's fine). But if the user clicks on an "update books" button in an Activity, can I still call theperformSync
method, or will it be disabled as well?
since
parameter)? The ContentProvider or a custom-defined service? And if the user exits theActivity
and re-enters it when the fetching hasn't completed yet, how can I know that there are some entities updating? I thought I could use the status column to get and set the status for any event: get, delete, and so on. – Dourine