0

I have a huge set of data that I want to insert into the sqlite database before the user is able to do anything inside my application. Right now I have all my data stored in CSV files, then I parse those files and use DatabaseUtils.InsertHelper to do a bulk insertion, but this is taking to long to complete.

I stumbled on this tutorial some time ago and I'm wondering: is it safe to distribute a pre-generated sqlite file? Can I run into problems due to different versions of SQLite on different devices?

I'm planning to support Android 2.1 and higher.

  • Yes, it is a little tricky but it can be done safely. – HandlerExploit Jul 25 '12 at 21:25
  • This app https://play.google.com/store/apps/details?id=com.sharecare.sos uses preloaded database. Quite many downloads, no complains regarding to lost data or any data related. – Maxim Jul 25 '12 at 21:30

2 Answers2

1

I suppose it depends on your definition of safe. It is certainly possible as long as the database conforms to the metadata table spec Android expects, which is what that tutorial you stumbled upon is showing you. You won't have to worry about version conflicts with SQLite as that is a package built into the core platform and isn't something OEMs add to or implement anything on top of.

However, if by safe you mean "protected" you would need to take special steps to ensure that your database is not externally readable if that is a concern. If you simply place the preconstructed DB into assets/ and copy it over, anyone who can properly deconstruct an APK file can view your database data. This may or may not be an issue for you.

devunwired
  • 62,780
  • 12
  • 127
  • 139
0

The best approach is to populate this data in the database, keep the database in assets & then copy it to the device ... You can follow this complete sample code here.

Community
  • 1
  • 1
Yaqub Ahmad
  • 27,569
  • 23
  • 102
  • 149