Persistent Data Storage in Smartphone Apps Part 2 – Building an Android app with a pre-created database. tagged:

Persistent Data Storage in Smartphone Apps Part 2 – Building an Android app with a pre-created database.

Posted by in BlackBerry, How-to

Not much documentation exists on how to access an existing SQLite database in Android without having to create the database from scratch within your app. However, its entirely reasonable to have a large data set best suited for storage in a database that you require to be shipped with the app.

Juan-Manuel FluxĂ  has written an excellent article on how to implement this in his post ‘Using your own SQLite database in Android applications‘. I’m not going to go through the details as he does a great job of explaining it but thought I’d mention one major drawback that you need to watch out for:

The approach involves including a SQLite database file in your application package; and then creating a copy of this database in the default database path of your application so that the app is able to access it. This is the only method I’ve come across to include a database in your app; the problem with it, however, is that you end up with two databases in your app, the initial one; and the copy that the app accesses. Should your data set be large, this becomes an inefficient and impractical use of space, with your application size becoming bloated. This was the case when I implemented attempted this method and as I wasn’t able to find a workaround; had to settle for using web services to download the initial dataset on first install. Not exactly elegant, but it got the job done!