Why should I use AsyncTaskLoader, and when should I prefer CursorLoader and vice-versa ?
In official page, the App-listing example is shown, this uses AsyncTaskLoader instead of CursorLoader.
What are the advantages and disadvantages of these two? I read somewhere about the CursorLoader not taking care about the content change (in sqlite).
Thank you!
AsyncTaskLoader is a abstract Loader that provides an AsyncTask to do the work.So you usually extend the AsyncTaskLoader to create your very own custom loader.The key difference between using a AsyncTask and using a AsyncTaskloader is that configuration changes (such as orientation change) do not affect AsyncTaskLoader and its processes since AsyncTaskLoader has its own lifecycle ;while the configuration changes affect the AsyncTask adversely since it is connected to host activity's lifecycle.
CursorLoader is a loader that queries the ContentResolver and returns a Cursor.This class implements the Loader protocol in a standard way for querying cursors.It is nothing but a AsyncTaskLoader.
In short,you can use AsyncTaskLoader when you have to create a custom loader by extending AsyncTaskLoader< D > where D="anything_you_want_to_load". And you use CursorLoader when you have to implement a loader which loads Cursor (usually used when you have load data from a database).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With