2

I have an sqlite database I want to distribute with my application. It's about 3mb. If I understand correctly, I can't directly open it if it resides in my app's /raw or /assets folder, right? We need to first copy it out of that directly as in:

Get the SQLite path within the Assets Folder

So my app will consume twice the disk space as it normally would? I don't understand why it's necessary to have the database file be in a particular folder?

Thanks

Community
  • 1
  • 1
user291701
  • 38,411
  • 72
  • 187
  • 285

1 Answers1

3

So my app will consume twice the disk space as it normally would?

Yes. Technically, probably more, as your database is compressed inside the APK file.

I don't understand why it's necessary to have the database file be in a particular folder?

It is not necessary for the database file to be in a particular folder. However, assets/ is a folder on your development machine; it is a part of the APK file on the device. Same goes for everything in res/raw/.

BTW, I recommend SQLiteAssetHelper for copying the database out of assets/.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Right so that's my confusion - we can read other assets directly from /assets or /raw without having to first copy them (or maybe this is done automatically for us at install time by the OS). The downside is that with a 3mb sqlite db, I need to (1) take a few seconds to copy it over at first startup, and (2) the 3mb is consumed both in the apk, and then in internal storage after the copy is complete. Understood there's nothing we can do about it, this is the way the system works, just seems like it could be better. Thanks – user291701 Jun 17 '12 at 12:51
  • @user291701: "we can read other assets directly from /assets or /raw" -- as an `InputStream`, yes, but not for random access, and not for modification. "just seems like it could be better" -- you are welcome to experiment with using the [APK expansion files](http://developer.android.com/guide/market/expansion-files.html) facility to have your databases be semi-automatically downloaded on first run. Or, you can download your database yourself on first run. – CommonsWare Jun 17 '12 at 12:54