首页 文章

有关在SQLite数据库中使用Android备份服务的问题

提问于
浏览
12

我的应用程序将所有用户数据和首选项存储在SQLite数据库中,我在Android's Data Backup Guide及其Android Backup Service中进行了一些阅读,但在开始之前仍然有一些问题 .

  • Is the data restored during install or on initial launch of my app? 即,在调用主Activity的代码之前文件是否存在?

  • If my SQLiteOpenHelper class already handles upgrades, is there anything else I have to do to handle restoration of an older db? 我假设没有,如果在我的应用程序启动之前存在数据库 .

  • Will I face concurrency issues when backing up because the BackupManager takes time? 如果用户输入新数据并且我调用 dataChanged() 然后在BackupManager调用 onBackup() 之前再次发生相同的情况,那么这些数据更改将如何处理? BackupManager是否只备份最新版本的数据库(应该包括两个更改)?

  • What problems will I face by trying to backup/restore a SQLite database? 我想've seen developers say that a database on one device may not be compatible with a database on another. I'只想使用 FileBackupHelper 备份数据库,因为it looks pretty simple to do . 至少有一位开发人员似乎有resolved at least some compatibility issues by disabling Write Ahead Logging . 如果我采用这种方法,我可以期待什么样的失败率?如果非常高,我可能会考虑转换为CSV文件并在此过程中返回 .

  • If a restore fails, can I catch it, inform the user, and save a copy of the troublesome data to storage? 用于故障排除并通知用户 .

  • The backup operation is "not threadsafe." Clarify how to handle. Android说,

要确保备份代理不会在活动的同时读取或写入文件,每次执行读取或写入时都必须使用synchronized语句 .

  • 这是否意味着我必须在 synchronized 语句中对数据库进行每次读/写操作?即,我必须将这个添加到我的活动从db加载或写入信息的每个地方?那是很多地方 .

  • 或者是否只表示备份代码必须使用 synchronized

谢谢您的帮助 . 我只是想做到这一点,让我的用户在今年圣诞节获得新手机时感到高兴!

1 回答

  • 1

    来自Android Documentation

    这应该回答你的1和2问题:

    Android automatically performs a restore operation when your application is installed and there 
    exists backup data associated with the user. The primary scenario in which backup data is restored 
    is when a user resets their device or upgrades to a new device and their previously installed 
    applications are re-installed.
    

    3:由于您的数据将在安装期间恢复,因此我认为您不会遇到并发问题

    4:

    Data backup is not guaranteed to be available on all Android-powered devices. However, your   
    application is not adversely affected in the event that a device does not provide a backup 
    transport. If you believe that users will benefit from data backup in your application, then you can 
    implement it as described in this document, test it, then publish your application without any 
    concern about which devices actually perform backup.
    

    5:我不这么认为 .

    6:“每次执行读或写”似乎都是不言自明的 . 每次在DB上执行操作时

相关问题