Reputation: 196
I have used Android AsyncTask and the AsyncTaskLoader. I want to know the reason why in some apps we use AsyncTask and in some we use AsyncTaskLoader. Is AsyncTask useless and we can use AsyncTaskLoader everywher? If yes then why? Please help me understand. Thank you.
Upvotes: 0
Views: 94
Reputation: 134
Official statement by Google:
AsyncTask was intended to enable proper and easy use of the UI thread. However, the most common use case was for integrating into UI, and that would cause Context leaks, missed callbacks, or crashes on configuration changes. It also has inconsistent behavior on different versions of the platform, swallows exceptions from doInBackground, and does not provide much utility over using Executors directly.
This class was deprecated in API level R.
And if briefly about the difference between these classes AsyncTaskLoader prevents duplication of background threads and eliminate duplication of destroyed activities.
Upvotes: 1