Getting Sqlitecursorloader To Observe Data Changes
Solution 1:
The Loader
documentation is flawed.
100% of Loader
implementations built into Android itself "monitor the source of their data and deliver new results when the contents change". Since there is only one Loader
implementation built into Android itself as of now, their documentation is accurate as far as that goes.
However, quoting a book update of mine that should be released in an hour or two:
There is nothing in the framework that requires this behavior. Moreover, there are some cases where is clearly a bad idea to do this – imagine a Loader loading data off of the Internet, needing to constantly poll some server to look for changes.
I do plan on augmenting SQLiteCursorLoader
to be at least a bit more aware of database changes, if you route all database modifications through it. That too will have limitations, because you don't share Loader
objects between activities (let alone have access to them from services).
The only reason CursorLoader
works as it does is because it uses a ContentProvider
-- a singleton that can therefore be aware of all operations.
At the moment, whatever portion of your code is responsible for inserts, updates, and deletes will either need to tap the SQLiteCursorLoader
on the shoulder and have it update, or notify the activity of the change (e.g., broadcast from a Service
) so the activity can tap the SQLiteCursorLoader
on the shoulder.
Post a Comment for "Getting Sqlitecursorloader To Observe Data Changes"