Miles Adamson
Miles Adamson

Reputation: 377

What is the best place for SQLite default entires?

I am creating (in android studio) an app which has a couple basic tables. One will be a bunch of exercises (pull ups, push ups ect) and I would like to put a ton of common ones into the table by default.

Where in my code would be the logical place to do that? I have made a databaseHelper class which extends SQLiteOpenHelper. Just not sure if I should..

  1. insert them all in onCreate()
  2. make a databaseHelper method which inserts them all and call it elsewhere
  3. other?

Upvotes: 0

Views: 40

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006614

Create a database with your desired data, package it as an asset, and use SQLiteAssetHelper to automatically unpack it into the proper spot for you when you first try to work with the database. This will be faster than running your own transaction(s) to insert the data.

Upvotes: 1

Related Questions