Workaround for Android SQLite3 issue with Titanium

For the new version of NeuroMind I am using Appcelerator’s Titanium for development. I like the ability to use standard web techniques in combination with the Titanium API to develop mobile apps for iPhone, iPod Touch, iPad and Android. My first completed project for all these devices is SNI Mobile, the mobile app for the open access journal Surgical Neurology International. This was fairly straightforward, except for the implementation of RSS feeds. Fortunately there is a good example available for this.

For NeuroMind I turned out to have a problem with using SQLite3 in Android 2.2 and Android 2.0.1. Strange, because the same code is working in Android 2.0 and Android 2.1-upd1. I finally decided for a workaround, where I use PHP to generate appropriate (Titanium-compatible) JavaScript-code from the SQLite database.

The full source code for the workaround is available here. Essentially I use the PDO-approach to combine PHP with SQLite3 (explained here). The script loads data from the SQLite3 database, and shows it as a twodimensional JavaScript array (demo). This can be copied & pasted into a separate *.js file that is used in the Titanium app via a simple Ti.include(). The array serves as the datasource for the tableview.

Although it is a little cumbersome, this workaround offers you the ability to use the SQLite3 database in iOS, and quickly convert it to an arrray for Android. At least this works on all versions I tested (2.0 – 2.2), and will prevent nasty errors on startup like this one:

Hopefully the future will bring an Android implementation that does not have troubles with the SQLite3 database.

Leave a Reply

Your email address will not be published. Required fields are marked *