-
Notifications
You must be signed in to change notification settings - Fork 1k
Pre populated databases
You can use a pre-populated database by following these steps:
-
Place a copy of the SQLite database file in the
assets
directory of your application, for example:/myapp/src/main/assets/prepop.db
-
Ensure you set the
AA_DB_NAME
in the manifest file, for example:<meta-data android:name="AA_DB_NAME" android:value="prepop.db" />
Now when you deploy your application it will copy the prepop.db
file from the assets
directory to /data/data/myapp/databases
storage.
Note: This will cause a duplication of the database as it will be both, packaged with the APK and copied to the storage directory.
To ensure the database works properly with ActiveAndroid take the following steps:
-
Setup the android_metadata table
CREATE TABLE "android_metadata" ("locale" TEXT DEFAULT 'en_US') INSERT INTO "android_metadata" VALUES ('en_US')
-
If you have not defined the
id
column name for your models, ensure the primary keys are renamed to the default,Id
, instead of_id
, which is the standard for Android databases. However, if your data is to be displayed inListViews
, for example, it is recommended to define your primary key columns as_id
. You can do this by simply adding aid = "_id"
param to the@Table
annotation on your model, like so:@Table(name = "Items", id = "_id") public class Item extends Model {