Reputation: 31
How do you re-copy a database that is stored in the assets folder for an android studio project?
I am using the Android SQLite Assets helper class
package com.acorney.migration;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
/**
* Created by acorney on 25/07/2016.
*/
public class databaseHelper extends SQLiteAssetHelper {
private static final String TAG = SQLiteAssetHelper.class.getSimpleName();
private static final String DATABASE_NAME = "peopleDatabase.db";
private static final int DATABASE_VERSION = 1;
public databaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
And I create an instance of it in my MainActivity
databaseHelper dataB;
dataB = new databaseHelper(this);
This, I think, creates an empty database in data/data and copies the database from Assets into it
However, I have updated the database from outside the app (using SQLite browser) and saved it back to the assets folder. How could I copy the database's updates into the application?
Eventually, the app needs to read and write to this database - so that changes are saved to the database in the assets folder
And, when the app starts up, the app should just create a new instance of the database in the assets folder.
Basically - I want all database changes to happen in the assets folder - is this something that can be done?
Thank you for your help
Upvotes: 1
Views: 1296
Reputation: 30088
No, this is not possible. The assets folder is part of the binary APK, which cannot be changed at runtime. You can only change it at compile time.
Upvotes: 1