If you know that your data model will not be changed later, you can create just "dumb" export of your database. DB is stored as a file in
public static final String CURRENT_DATABASE_PATH = "data/data/" + App.getContext().getPackageName() + "/databases/" + DatabaseHelper.DATABASE_NAME
where DATABASE_NAME is your name used when creating DB.
Here are the methods I use (I'm not an author, this code is strongly inspirated by some other stackoverflow thread which I can't find right now)
Export:
public static void exportDB() {
try {
File dbFile = new File(CURRENT_DATABASE_PATH);
FileInputStream fis = new FileInputStream(dbFile);
getExportDirectory();
String outFileName = createExportName();
OutputStream output = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = fis.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
output.flush();
output.close();
fis.close();
} catch (Exception e) {
App.log(e);
}
}
And again for import
public static boolean importDB(String dbPath) {
try {
AppStorage.get().close();
File newDb = new File(dbPath);
File oldDb = new File(CURRENT_DATABASE_PATH);
if (newDb.exists()) {
copyFile(new FileInputStream(newDb), new FileOutputStream(oldDb));
AppStorage.get().getWritableDatabase().close();
}
AppStorage.reset();
return true;
} catch (Exception e) {
App.log(e);
}
return false;
}
However, if you plan to update your data model this approach would not work, so you'll probably need to manualy export/import everything you want to.
Edit: AppStorage is my custom db wrapper. This approach won't delete your database.