In our app, we load data from sqlite and reflect it on UI. Sometimes the app become irresponsive when such operation occur. What will the option should be used to perform db operations in background thread and return result to UI thread. I found two choices 1. AsyncTask 2. Loaders. Which will be the best one?
Asked
Active
Viewed 300 times
-5
-
A small AsyncTask to load the data in doInBackground, and then in onPostExecute you can update your UI. Works wonders. – Andreas Engedal Sep 20 '17 at 09:14
-
I prefer to use [AsyncTaskLoader](https://developer.android.com/reference/android/content/AsyncTaskLoader.html). This is best as compare to AsyncTask. you can see [here](https://stackoverflow.com/a/7122836/7073808) – UltimateDevil Sep 20 '17 at 09:43
1 Answers
0
Android Developer Official documentation says this About using Loader API over AsyncTask
If you fetch the data from another thread, perhaps with AsyncTask, then you're responsible for managing both the thread and the UI thread through various activity or fragment lifecycle events, such as onDestroy() and configurations changes.
You can find more comparison among two
Loader vs AsyncTask
ASYNCTASK VS LOADERS : WHY LOADERS ARE INTRODUCED?

Rohit Singh
- 16,950
- 7
- 90
- 88