Users often invest significant time and effort creating data and setting preferences within apps. Preserving that data for users if they replace a broken device or upgrade to a new one is an important part of ensuring a great user experience. This section covers techniques for backing up data to the cloud so that users can restore their data.
To preserve as much of an existing user's experience on a new device as possible, make sure you backup the following user settings:
- Any settings modified by the user, for example using a
- Whether the user has turned notification and ringtones on or off.
- Boolean flags which indicate if the user has seen welcome screens or introductory tooltips.
You must not backup URIs for ringtones because URIs are unstable. In some cases a restoration to a new mobile device may result in a URI which points to no ringtone, or a different ringtone from the one intended. Instead, you can backup ringtones using either their title or a hash of the ringtone.
Android provides two ways for apps to backup their data to the cloud: Auto Backup for Apps and Key/Value Backup. Auto Backup, which is available starting API 23, preserves app data by uploading it to the user's Google Drive account. The Key/Value Backup feature (formerly known as the Backup API and the Android Backup Service) preserves app data by uploading it to the Android Backup Service.
Generally, we recommend Auto Backup because it requires no work to implement. Apps that target Android 6.0 (API level 23) or higher are automatically enabled for Auto Backup. The Auto Backup feature does have some limitations in terms of what data it can backup and it's availability on Android 6.0 and higher devices. Consider using the Key/Value Backup feature if you have more specific needs for backing up your app data. For more information, see Comparison of Key/Value and Auto Backup.
You can also maintain existing user engagement on a new device by providing a seamless login experience. You can integrate Smart Lock for Passwords into your Android app to restore user sign-ins on a mobile device. Smart Lock for Passwords supports saving both username-password credentials and federated identity provider credentials.
For synchronizing app data, see Transferring Data Using Sync Adapters or Google Drive Android API. Neither backup approach is designed for ongoing synchronization of app data between Android-powered devices or saving data which you'd like to use during the normal application lifecycle. You cannot read or write backup data on demand. However, if your app doesn't have a backup mechanism for app contents and the size of your app contents is unlikely to exceed the 25 MB limit, then Auto Backup may be sufficient for your needs.
Note: If Wi-Fi isn't available, Key/Value Backup may use mobile data. Key/Value Backup is therefore typically not suitable for app data contents, such as media, downloaded files, and caches, unless the amount of data is very small.