Backup dữ liệu android

Users often invest significant time & effort creating an identity,adding data, & customizing settings và preferences within your tiện ích.Preserving this data và personalization for users when they upgrade lớn anew device or re-install your ứng dụng is an important part of ensuring agreat user experience. This page describes what data you should baông chồng up andthe backup options available khổng lồ you.

Bạn đang xem: Backup dữ liệu android

Select which data lớn back up


Figure 1. Make sure you restore identity, tiện ích data, và settings data for users returning to your tiện ích.

Users generate a lot of data when using your apps and you should take care tobaông xã up the appropriate data. Only backing up some of the data canfrustrate users when they open the tiện ích on a new device and discover somethingmissing. The important data to baông xã up for your users is their identity data,user-generated ứng dụng data, and settings data, as described below.

Identity data

You can help maintain existing user engagement by transferring theuser's trương mục when they get started with a new device.

To begin, you should adopt GoogleSign-In, which allowsusers khổng lồ log-in automatically or with a single tap on their new device.

You can also integrate Smart Lochồng forPasswords,which instantly restores user sign-ins on a device. Smart Loông chồng for Passwordssupports saving both username-password credentials (for example, passwords) andfederated identity provider credentials. The AutofillFramework also allows users lớn save sầu passwords on devices running vienchinh.biz8.0 and higher.

You can also use the Account TransferAPI to copy over custom accountcredentials for your phầm mềm from a user's existing device to a new device. Thetransfer takes place during setup of the new device over an encrypted Bluetoothconnection or device-to-device cable.

App data

App data may include user-generated content, such as text, images, andother truyền thông media. For restoring tiện ích data, see Transfer data using syncadapters or Google Drive vienchinh.bizAPI. You can use either approachkhổng lồ synchronize ứng dụng data between devices và save data whichyou'd lượt thích khổng lồ use during the normal phầm mềm lifecycle. You can also use eitherapproach to restore a returning user's data onlớn a new device.

Settings data

Make sure you also baông chồng up và restore settings data to lớn preservea returning user's personalized preferences on a new device. You canrestore settings data even if a user doesn't log in to your phầm mềm. You canbachồng up settings that a user explicitly sets in your app's UI, as well astransparent data, such as a flag indicating whether a user has seen athiết đặt wizard.

Note: Any permissions a user grants lớn your app are automatically backed up và restored by the system on devices running version 7.0 (API cấp độ 24) & higher. However, if a user uninstalls your app, then the system clears any granted permission & the user must grant them again.

Xem thêm: Cách Biến Laptop Thành Loa Bluetooth Trong Windows, Ghép Thiết Bị Bluetooth Trong Windows

To preserve sầu as much of an existing user's experience on a new device aspossible, make sure you baông chồng up the following user settings:

Whether the user has turned notification and ringtones on or off.

Boolean flags which indicate if the user has seen welcome screens orintroductory tooltips.

Figure 2. Restoring settings on new devices ensures a great user experience.

One type of settings data you should avoid backing up is URIs because theycan be unstable. In some cases a restoration lớn a new di động device may resultin an invalid URI that does not point to lớn a valid file. One example of this isusing URIs khổng lồ save a user's ringtone preference. When the user reinstalls theứng dụng, the URI might point lớn no ringtone, or a different ringtone from the oneintended. Instead of backing up the URI you can instead back up some metadataabout the setting, such as a ringtone title or a hash of the ringtone.

Backup options provides two ways for apps to lớn bachồng up their data khổng lồ the cloud:Aukhổng lồ backup for apps & Key/ValueBackup. Aukhổng lồ Backup, which is available version 6.0 and higher, preserves data by uploading it lớn the user'sGoogle Drive sầu account. Auto Backup includesfiles in most of the directories that areassigned lớn your phầm mềm by the system. Auto Backup can store up to 25 MB offile-based data per phầm mềm. The Key/Value Backup feature (formerly known as theBackup API & the Backup Service) preserves settings data in the formof key/value pairs by uploading it lớn the Backup Service.

Generally, we recommover Aukhổng lồ Backup because it's enabled by default & requiresno work khổng lồ implement. Apps that target version 6.0 or higher areautomatically enabled for Auto lớn Backup. The Auto lớn Backup feature is a file-basedapproach lớn backing up tiện ích data. While Aukhổng lồ Backup is simple khổng lồ implement, youmay consider using the Key/Value Backup feature if you have more specific needsfor backing up data.

Note: If your tiện ích doesn't have a backup mechanism for ứng dụng contents and the kích cỡ of your app contents is unlikely lớn exceed the 25 MB limit, then Aukhổng lồ Backup may be sufficient for your needs.

The following table describes some of the key differences betweenKey/Value Backup và Auto Backup:

Category Key/Value Backup ( Backup Service) Aukhổng lồ Backup App shut down
Supported versions 2.2 (API cấp độ 8) and higher. 6.0 (API màn chơi 23) and higher.
Participation Disabled by default. Apps can opt in by declaring a backup agent. Enabled by default. Apps can opt out by disabling backups.
Implementation Apps must implement a BackupAgent. The backup agent defines what data to baông xã up and how to lớn restore data. By default, Aulớn Backup includes almost all of the app"s files. You can use XML to lớn include & exclude files. Internall, Auto lớn Backup relies on a backup agent that is bundled into lớn the SDK.
Frequency Apps must issue a request when there is data that is ready khổng lồ be backed up. Requests from multiple apps are batched & executed every few hours. Backups happen automatically roughly once a day.
Transmission Backup data can be transmitted via Wi-Fi or cellular data. Backup data is transmitted using Wi-Fi by mặc định, but the device user can turn on mobile-data backups. If the device is never connected to a Wi-Fi network or the user doesn"t change their mobile-data backup settings, then Aukhổng lồ Backup never occurs.
Transmission conditions Define device conditions required for backup in onBackup(). Define device conditions required for backup in XML file (if using the default backup agent).
Apps are not shut down during backup. The system shuts down the tiện ích during backup.
Backup storage Backup data is stored in Backup Service & limited khổng lồ 5MB per app. Google treats this data as personal information in accordance with Google"s Privacy Policy. Backup data is stored in the user"s Google Drive sầu limited to 25MB per tiện ích. Google treats this data as personal information in accordance with Google"s Privacy Policy.
User login Doesn"t require a user to be logged into lớn your ứng dụng. The user must be logged into the device with a Google account. Doesn"t require a user to be logged inlớn your app. The user must be logged inkhổng lồ the device with a Google account.
API Related API methods are entity-based: Related API methods are file-based:
Data restore Data is restored when the ứng dụng is installed. If needed, you can request a manual restore. Data is restored when the ứng dụng is installed. Users can select from a danh sách of backup datasets if multiple datasets are available.
Documentation Baông chồng Up key-value pairs with Backup Service Baông xã up user data with Auto lớn Backup

More information about how backup & restore works for each service isavailable in Test backup và restore.

Note: If Wi-Fi isn't available, Key/Value Backup may use Mobile data. Key/Value Backup is therefore typically not suitable for ứng dụng data contents, such as truyền thông, downloaded files, và caches, unless the amount of data is very small.