Android data storage-Data Backup (1)

Source: Internet
Author: User

The backup service of Android allows you to copy persistent application data to remote "Cloud" storage, so as to provide a restore point for application data and settings. If you restore the factory settings or convert the application to a new Android device, the system automatically restores the backup data when the application is re-installed. In this way, the user does not need to copy the data or set the previous data. This process is completely transparent to users and does not affect functions or user experience in applications.

During the backup operation, the android backup Manager (backupmanager object) queries the data to be backed up by the application, and then delivers the data to a backup transmitter, send data to the cloud storage. During the recovery operation, the backup manager obtains the backup data from the backup transmitter and returns it to the application so that the application can recover the data to the device. It is possible for the application to request data recovery, but this is not necessary, because when the application is followed and the backup data associated with this user exists, android automatically performs a recovery operation. The main scenario for restoring backup data is when the user resets the device settings, upgrades to a new device, and re-installs the previously installed applications.

Note: The backup service is not designed to synchronize application data. Therefore, backup data cannot be read and written as needed, and backup data cannot be accessed through APIS provided by the backup manager.

The backup transmitter is a client component of the android backup framework. It can be customized by the device manufacturer or service provider. The backup transmitter may vary depending on the device, and the backup transmitter on any device is transparent to the application. The backup manager API isolates the application from the actual backup transmitter on the given device. That is to say, the application communicates with the backup manager through a set of fixed APIs, regardless of the underlying data transmission.

The Data Backup component is not always available on all Android devices. However, even if a device does not provide a backup transmitter, the application will not be adversely affected. If it is determined that the user will benefit from the data backup of the application, you can implement it according to the description in this document, and then release the application that is irrelevant to which devices actually perform the backup operation. In this way, when the application runs on a device that does not provide the backup transmission function, the application can also operate normally, but does not accept the callback of the backup data from the backup manager.

Backup data cannot be read by other applications on the device. Only the backup manager and backup transmitter can access the data to be backed up during the backup operation.

Warning because the cloud storage and transmission services may vary with devices, Android does not guarantee the security of backup data. Therefore, you must always be cautious when backing up sensitive data, such as user name and password data.

Basic

To back up application data, you must implement a backup proxy. The backup manager calls the backup proxy to provide the data to be backed up. The proxy is also called to restore data when the application is re-installed. The backup Manager processes all data transactions related to cloud storage (using a backup TRANSMITTER), and the data backup proxy processes all data transactions related to local devices.

Follow these steps to implement the backup Proxy:

1. Use the Android: backupagent attribute in the configuration file to declare the backup proxy;

2. register the backup service for the application, Google provides Android Backup Service (https://developers.google.com/android/backup? Hl = ZH-CN) is used as a backup service for most Android devices. To make this service work, it requires that the application be registered to this service. To save data to the server, you may need to register some other available backup services.

3. Define the backup proxy in one of the following ways:

A. inherit the backupagent class

The backupagent class provides core interfaces for communications between applications and Backup management. If you inherit this class directly, you must override the onbackup () and onrestore () methods for processing
Back up and restore data.

B. inherit the backupagenthelper class

The backupagenthelper class provides convenient encapsulation for the backupagent class, which only requires a small amount of code. In the extended class of backupagenthelper, one or more helper objects must be used to automatically back up and restore certain types of data, so you do not need to implement onbackup () on your own () and the onrestore () method.

Android currently provides backup and recovery helper for sharedpreferences and internal storage files.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.