New Features of Android M-automatic backup of application data and new features of android

Source: Internet
Author: User

New Features of Android M-automatic backup of application data and new features of android
I. Features

Android m's automatic data Backup function uses Android Backup Service to back up data to google drive. Android Backup Service is available in Android 2.2. However, Google's backup service was not used to synchronize and back up application data at the beginning, but to facilitate users to obtain the backup data on different devices. Now, as long as your app data changes or the system is upgraded, the app data backup function of Android M is enabled. Therefore, the application can restore the previously stored data at any time, even if the device has recovered the factory settings or changed the new device. In this way, the game will remember where the user is paused during the game process, and the application can also save login information and preference settings.

However, the automatic backup function is also restrictive.

On the one hand, each app can only back up to 25 MB of data. The original article is as follows:

On the other hand, for applications that use Google cloud message push notifications, there is a known problem, that is, backing up the registration id returned by Google cloud Information Registration will break the push of the recovered application. Therefore, after the app is installed on a new device, it is very important to ask the API to obtain a new registration id. However, if you back up the old registration id, the app installed on the new device will not ask the API to obtain the new registration id. To avoid this problem, configure the exclude label in xml. Generally, the device id is generated based on the device and cannot be used. However, if you back up the previous id information, the new device will not generate new information. The original article is as follows:

Ii. Backup

The Automatic Backup Service supports setting backup rules through the XML configuration file and app manifest.

In app manifest, you only need a line of code to specify the xml file to introduce the rule (mybackupscheme is the xml file name)

 

Configure the rules in xml.

 

· <Include> specify the file to be backed up

· <Exclude> specifies files not backed up

· Domain specifies the file type

· Path specifies the file path to be backed up

 

Then how does Android M implement automatic backup of the app? In fact, it reads the app manifest by obtaining the read and write permissions of the app, and then writes the relevant backup configuration in it.

 

Iii. Recovery

When data needs to be restored, Backup Manager will first call the requestRestore () method to download data from google drive

 

Call the onStore () method to recover the data to your device. This method requires three parameters.

· Data: A BackupDataInput that allows you to read the backup data.

· AppVersionCode: the android: versionCode attribute value in your application. It can be used to determine whether the application data is compatible with the data format backed up on the cloud.

· NewState: an open, read-write object that points to the ParcelFileDescriptor of the file that stores the final data backup state. this object will be returned with the oldState variable name during the next onBackup call.

 

When the onStore () method is executed, the readNextHeader () method is called to traverse all objects in the Data Group. Each time an object is found, the following operations are performed:

2. compare the object key with all the static final type key values declared in the BackupAgent class. Once it matches one of your existing key values, the data downloaded from the cloud is extracted and saved to your device.

 

The helper. restoreEntity () method is used to save the data. It writes the data to the file that matches the key.

 

4. Can we implement it?

As mentioned above, Google implements automatic backup by obtaining the read and write permissions of other apps and writing corresponding configurations in the app to implement backup. Why can Google obtain the read and write permissions of other apps? Because he has system permissions, he has read and write permissions for all apps installed in his system. However, the app and the app cannot obtain the read and write permissions of the other party. Android applications use the Linux Sandbox technology to isolate different apps. The main isolation between apps is resource isolation and permission access isolation. Although the APP permission mechanism provides the possibility of mutual access of resources between applications, apps can access services of other programs after applying for permissions and being authorized by users. However, both apps need to be configured in the code. First, use the same private key as the signature to ensure that the two apps are running in the same process. Then, you need to customize the <permission> tag to ask whether you want to obtain the read and write permissions of the app. But this is not practical. We cannot cooperate with all apps, so that they can add the configuration in the program code that allows us to get their read and write permissions.

Related Article

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.