You can make a copy of the database in your external storage but in a different route than the one used by your application.
Example, assuming your application has a package name called "com.kevtho.app"
, you can use a different package to define another route, for example:
if you generate this route:
String mypath = Environment.getExternalStorageDirectory().getPath() +
"/Android/data/com.kevtho.basededatos/misbd";
by deleting your application this route that would contain the database, would remain intact.
Depending on the amount of data, if they are considerable or if it is more sensitive information, you may consider consuming a Web Service.
What this article mentions:
Sqlite Backup to the sdcard unit on Android , it works but it is important that you change the name of the package to a different one from your application so that when it is deleted the data is not deleted.
public void backupdDatabase(){
try {
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
String packageName = "com.yourapp.package";
String sourceDBName = "mydb.db";
String targetDBName = "mydb";
if (sd.canWrite()) {
Date now = new Date();
String currentDBPath = "data/" + packageName + "/databases/" + sourceDBName;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm");
String backupDBPath = targetDBName + dateFormat.format(now) + ".db";
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
Log.i("backup","backupDB=" + backupDB.getAbsolutePath());
Log.i("backup","sourceDB=" + currentDB.getAbsolutePath());
FileChannel src = new FileInputStream(currentDB).getChannel();
FileChannel dst = new FileOutputStream(backupDB).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
}
} catch (Exception e) {
Log.i("Backup", e.toString());
}
}