Recently we worked with big databases under android, and during that I met query optimization problems when using subqueries.
From my previous experiences with MySQL I thought, the database engine optimization is always the best, and there is no way, that multiple queries from program code is better, but I ended running multiple selects in a loop in this case for the best result.
In android it is highly important to use transactions when working with databases.
First, in android database operations - especially writing - are very slow. Batching them into transactions will make them much faster.
Second, the database remains consistent under any circumstances. The database system makes sure to all the operations in a transaction take effect, or on error, rollback all of them.
If you are used to other platforms like PHP+MySQL where the code usually runs on a powerful server, witch is not likely to stop execution "unexpectedly", you can be surprised how much it affects the performance in android.
The android system can kill apps/threads/activities and so interrupt database usage, the battery can discharge or can be removed etc.
The implementation is very simple, using 3 methods in the SQLiteDatabase class:
When I first tried to manage an sqlite database on an android device I was not sure about where I fail in it. Can I even insert the records into the database, or I fail only to read the data from it? So I started to search for possibilities to debug the database lifecycle.
The system stores databases in the /data/data/package_name/databases folder by default.
In a command line using the adb (Android Debug Bridge - found in the android sdk tools library) you can access the databases on a running emulator like below:
In Hello Android's first tutorial we will walk through creating a simple RSS reader. This tutorial will show you how to parse XML files and use the SQLiteDatabase for storage.