CursorLoader
is part of the loader family. Before we dive deep into an example explaining how to use CursorLoader
, we will explore a bit about loaders and why it is important in the current scenario.
Introduced in HoneyComb (API level 11), loaders serve the purpose of asynchronously serving data in an activity or fragment. The need to have loaders arose from many things: calls to various time-consuming methods on the main UI thread in order to fetch data that leads to a clunky UI, and even in some cases, the dreaded ANR box. This is demonstrated in the following screenshot:
For example, the managedQuery()
method, which was deprecated in API 11, was a wrapper around the ContentResolver'squery()
method.
In the previous chapter, while highlighting how to fetch data from a content provider inside the query method, we used getContentResolver.query()
instead of managedQuery()
. Using deprecated methods can lead to problems with future releases and should be...