I've read many tutorials, and have code working where I can play with databases using Eclipse and the Android emulator. However, whenever I put the apk on a device, the database is empty. I'm running in circles trying to figure out how to put my populated database on a device WITH the apk. Can anyone explain what I need to do or point me to a tutorial?
Asked
Active
Viewed 66 times
1
-
Did you read this http://stackoverflow.com/questions/513084/how-to-ship-an-android-application-with-a-database ? – marsei Sep 04 '13 at 21:18
-
The only problem with moving it with the apk as the post Magla alluded to shows, is you will either never be able to write to it (just read) OR, if you copy it into your device, you will have 2 databases with the same info (thus taking up unnecessary space) – Raigex Sep 04 '13 at 21:30
-
I had seen that post (Magla). I had looked into it a bit, but it just seemed way too convoluted to do. I looked into a few of the ideas ... I was hoping there was a more "standard" way to do it. I ended up using SQLiteAssetHelper (which was mentioned once in that link). I got my code working with it, and it's working great on devices. I haven't gotten too deep into the inner workings, but it appears you zip your database, which is then rolled into the apk, and that's it. You can read and write to it. – CorporalCuddler Sep 05 '13 at 17:27
1 Answers
0
SQLiteAssetHelper
allows you to put your ZIPped SQLite database in your project's assets/
directory, then unpack it into its proper location on first use. After that, it works largely like SQLiteOpenHelper
, which you may already be using.
Here is a sample application demonstrating its use.

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
-
This is what ended up working for me. I had seen links to this, but hadn't gotten too deep into it. It's absolutely ridiculous to me that Android doesn't have a better way to deal with pre-populated databases. It appears Jeff Gilfelt wrote this library that does in fact make it possible to wrap a zipped database into the apk. You can read and write to it. My existing code will have to be changed a bit to use this, but I don't think it will be too much work. Right now I have a DBAdapter class and a class for each table in the database. Anyway, this worked for me. Thank you very much. – CorporalCuddler Sep 05 '13 at 17:21