问题
My app uses a small SQLite database that I'd like to have backed up. I'm assuming this won't happen automatically, without my coding for it using fullBackupContent, shown below. How do I modify the content of my backupscheme.xml to set the include path correctly? I prefer to set the db location at runtime.
My backupscheme.xml looks like
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content >
<include domain="database" path="device_info.db"/>
</full-backup-content
My manifest contains:
<application
android:allowBackup="true"
android:icon="@drawable/time_machine_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name="mypackage.myapp"
android:fullBackupContent="@xml/backupscheme"
>
回答1:
<include domain="database" path="device_info.db"/>
Here, the domain indicates the root directory in which the path
is interpreted. database
maps to where SQLite databases are stored by default, if you use:
getDatabasePath()
onContext
SQLiteOpenHelper
with just a plain filenameopenOrCreateDatabase()
with just a plain filename
In that case, the filename should be your path
value.
If your database is stored somewhere else for some reason, the <include>
directive would need some adjustment.
来源:https://stackoverflow.com/questions/35801374/automatically-backing-up-sqlite-database