Loaders provide a framework for the asynchronous loading of data.
They are registered by id in the loaderManager. The loader Id has to be unique for all loader used in the activity.
You can use:
- or define your loader by implementing AsyncTask
Disadvantage of querying the database from the UI
- The query could take a long time
- The activity could stop before it completes
- The cursor is tied to the activity, so if the activity restarts, the data must be re-queried
Android 2.3 compatibility with the below imports. android.support.v4. is used to write apps that run on platforms prior to Android 3.0.
import android.support.v4.app.Fragment; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.support.v4.content.CursorLoader;