I implemented BackupAgentHelper using the provided FileBackupHelper to backup and restore my own database, which I have. This is the database that you usually use with ContentProviders and which is located in /data/data/yourpackage/databases/ .
You might think that this is a common case. However, the docs are not clear what to do: http://developer.android.com/guide/topics/data/backup.html . For these typical databases, there is no BackupHelper . Therefore, I used FileBackupHelper , pointing it to my .db file in " /databases/ ", presented locks around any db operation (for example, db.insert ) in my ContentProviders and even tried to create " /databases/ " before onRestore() , because that it does not exist after installation.
I have implemented a similar solution for SharedPreferences successfully in another application in the past. However, when I test my new implementation in emulator-2.2, I see that the backup is being performed in LocalTransport from the logs, and the restore (and onRestore() ) is also running. However, the db file itself is never created.
Please note that this is all after installation and before the first launch of the application after recovery. In addition, my testing strategy was based on http://developer.android.com/guide/topics/data/backup.html#Testing .
Also note that I'm not talking about some sqlite database that I manage myself, nor about backing up to SDcard, my own server, or anywhere else.
I saw a mention in the docs on databases suggesting using a custom BackupAgent , but that doesn't seem like a link:
However, you can expand BackupAgent directly if you need to: * Back up data in a database. If you have a SQLite database, you want to restore when the user reinstalls your application, you need to create a custom BackupAgent that reads the corresponding data during the backup, then create tables and insert the data during recovery.
Some clarity please.
If I really need to do this on my own up to the SQL level, then the following topics concern me:
Open databases and transactions. I do not know how to close them from such a singleton class outside the workflow of my application.
How to notify the user that the backup is in progress and the database is locked. This can be time consuming, so I may need to show a progress bar.
How to do the same when recovering. As I understand it, recovery can only happen when the user has already started using the application (and enters data into the database). Therefore, you cannot just allow to restore backup data in place (deleting empty or old data). You will have to somehow join it, which is impossible for any non-trivial database because of the identifier.
How to update the application after recovery is complete, without forcing the user to get stuck in some now inaccessible point.
Can I be sure that the database has already been updated during backup or restore? Otherwise, the expected pattern may not match.
android database restore android-backup-service
pjv Mar 12 2018-11-12T00: 00Z
source share