I need to learn how to use databases for my application, so I have decided to go with vogella's tutorial as most of his other tutorials are very helpful. I just have a few questions to make sure my application will be compatible across devices.
He mentions that his tutorial will use the Async loader class
This tutorial describes how to use the SQLite database in Android applications. It also demonstrates how to use existing ContentProvider and how to define new ones. It also demonstrates the usage of the Loader framework which allows to load data asynchronously.
http://developer.android.com/reference/android/content/AsyncTaskLoader.html shows that the minimum API level is 11?
How should I go about learning SQLite in Android? Should I use this tutorial? I want to make sure I'm using the best standards, yet getting compatibility as far back as possible (At least API level 7)
2 Answers 2
It's generally best practice to make SQLite calls asynchronously. You could use the Android support library which has AsyncTaskLoader, but I usually just extend AsyncTask, which was introduced in API level 3.
5 Comments
AsyncTask is very quick and easy to implement, but it can potentially cause memory-leak issues if you have changing screen orientations mid-execution. AsyncTaskLoader is better to use if this is a concern for your application, but Loader is a newer API so again, you either need to use the support jar or simply use a higher API level. Using CursorLoader is probably the most "right" way to do it.The AsyncTaskLoader is supported using the Android support library
http://developer.android.com/tools/extras/support-library.html
back to V4. CursorLoader (subclass of AsyncTaskLoader) is the preferred way for handling SQLite transactions while maintaining smooth UI flow on Android. Note that CursorLoader does require the use of a ContentProvider, so it's worth looking at ContentProviders as well.
Comments
Explore related questions
See similar questions with these tags.