0

I created an android application and everything works fine. It uses SQLite database into which after calling the onCreate method values are inserted and later requested.

In my opinion it is a waste of performance if i fill it whenever the onCreate is called. When i deliver the application to a user I would like to give this prefilled database(it will not change any more), so that

  1. it is not refilled whenever onCreate is called
  2. it is not necessary any more to have data - which should be inserted - hardcodedcin my code

Is there any possiblity to do this, or is my only option to fill it during runtime?

Jonas1902
  • 93
  • 1
  • 10

2 Answers2

1

Try this guide: Using your own SQLite database in Android applications

1

In my opinion it is a waste of performance if i fill it whenever the onCreate is called

Normally, onCreate() on a SQLiteOpenHelper is called once per app installation. More directly, onCreate() is only called if the database needs to be created, because the database does not already exist. So, "out of the box", "it is not refilled whenever onCreate is called".

When i deliver the application to a user I would like to give this prefilled database(it will not change any more)

Use SQLiteAssetHelper.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491