1

I have read that Loaders monitor the underlying data-source for changes, and load new data whenever it becomes available.

My question is that when would the data in the data source change? Any examples will be appreciated.

  • Forexample let's say an app uses a user-entered search query to perform search, and the search results are returned in an array. So since we have performed the search once, and the search results have been received in the array, in what cases could this data in the returned array change (which is being monitored by the Loader) ?
Solace
  • 8,612
  • 22
  • 95
  • 183

1 Answers1

2

My question is that when would the data in the data source change?

That would depend on the data source. In the classic case of CursorLoader, the data would change if the contents of the ContentProvider change, by something calling methods like insert() on a ContentResolver.

in what cases could this data in the returned array change

If something modifies the data in the data source such that the search results change, such as by deleting items that had formerly been returned in the search.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • _"If something modifies the data **in the data source** such that the search results change"_ . But once the search is carried out, the search results retrieved are on the client side, and any changes in the data sitting on the server will not be reflected in the data we have already retrieved through our search, isn't it? – Solace Jun 30 '15 at 02:36
  • @Solace: A `Loader` implementation is supposed to be notified of data changes, so it can load fresh data and deliver it to the `LoaderCallbacks`. In the case of `CursorLoader`, that would be handled by means of a `ContentObserver`. There are no other `Loader` implementations in the Android SDK, and this requirement of the `Loader` framework makes it difficult to create independent reusable implementations. – CommonsWare Jun 30 '15 at 09:46