My app stores all user data and preferences in a SQLite database, which I'd like to persist if the user gets a new phone, reinstalls, or does a factory reset. I've done some reading in Android's Data Backup Guide and their Android Backup Service, but still have some questions before I get started.
dataChanged()
and then the same happens again before the BackupManager calls onBackup()
, how will these data changes be handled? Will the BackupManager simply backup the latest version of the database (which should include both changes)? FileBackupHelper
, because it looks pretty simple to do. At least one developer seems to have resolved at least some compatibility issues by disabling Write Ahead Logging. If I take this approach, what rate of failure might I expect? If very high, I might look into converting to a CSV file and back during the process. To ensure that your backup agent does not read or write your files at the same time as your activities, you must use synchronized statements each time you perform a read or write.
synchronized
statement? i.e., I have to go add this to every place my Activities load from the db or write info to it? That's a lot of places.synchronized
?Thanks for the help. I just want to do this right and keep my users happy when they get new phones this Christmas!
From Android Documentation
This should answer your 1 and 2 question :
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: Since your data will be restored during installation i don't think you will face concurrency problems
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: I don't think so.
6: "each time you perform a read or write" seems to be self-explanatory. Every time you you do an operation on the DB
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With