Automatically backing up SQLite database

倾然丶 夕夏残阳落幕 提交于 2019-12-24 00:39:44

问题


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() on Context
  • SQLiteOpenHelper with just a plain filename
  • openOrCreateDatabase() 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!