IndexedDB Example on Cordova (Phonegap) - Android

Get the source and run on Eclipse
The last blog post demonstrated using the IndexedDB API on Cordova (Phonegap) - iOS. Using the IndexedDB API was simple; with just a requirement to add a delay to IndexedDB operations so that the IndexedDB polyfill can be done with its housekeeping database activities. 
This post takes the idea furthur and demonstrated the use of IndexedDB with Cordova on Android based devices. The source code is available here and can be opened with Eclipse to see it in action. The screenshots below show it in action. 



Getting it to work on Android gets a little trickier. The IndexedDB Shim starts doing housekeeping tasks like creating tables for database versions, etc. as soon as it is loaded. In case of Android, WebSQL operations must be performed till the deviceready is fired. In case such an operation starts, the native implementation seems to kick in and all future operations seem to fail.
To overcome this limitation of the polyfill, the polyfill is injected using javascript within the deviceready event, thus starting the housekeeping only after Cordova is ready. A way to fix this in the polyfill would be to watch out for a flag that lets the housekeeping start, and raise an event when the housekeeping is done, but this approach would make the polyfill harder to use.

Watch out this space for updates on my experiments with IndexedDB. Next activity - getting it to work with Windows Phone 7 ? B2G already supports it natively !!