Search code examples
androidloaderandroid-searchasynctaskloader

Android Loaders: When and why would the data content in the data-source change?


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) ?

Solution

  • 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.