Android M new Features-Application Data automatic backup function

Source: Internet
Author: User

A. function Introduction

Android M's automatic backup Data feature uses the Android backup Service, which backs up data to Google Drive. Android Backup service is actually available on Android 2.2. But at first Google's backup service was not used to synchronize backup application data, but to make it easier for users to get backup data on different devices. Now, as long as your app data changes, or when the system is upgraded, the Android m app data backup function starts. So the app can restore previously stored data, even if the device has been reset to factory settings or replaced with a new device. This way, the game remembers where the user paused during the game, and the app can save the login information and preferences.

However, the automatic backup function also has a certain limitation

On the one hand, it can only back up 25MB of data per app. The original text reads as follows:

On the other hand, for applications that use Google Cloud messaging push notifications, there is a known issue that backing up Google Cloud Information registration returns the registration ID that will break the push of the recovery application. So when the app is installed on a new device, it's important to ask the API to get a new registration ID, but if you back up the old registration ID, the app installed on the new device won't ask the API for a new registration ID. So in order to avoid this problem, the exclude tag in the XML should be configured accordingly. Easy to understand, the general Device ID information is to be generated based on the device, can not use the old. But if you back up your previous ID information, the new device won't generate new information. The original text reads as follows:

two. About Backup

The automated backup service supports the provisioning of backup rules through XML configuration files and app manifest.

In app manifest, you only need one line of code to specify the XML file you want to introduce the rule to (Mybackupscheme is the XML filename)

Then configure the appropriate rules in the XML to

· <include> specify the files to be backed up

· <exclude> specify files that are not backed up

· Domain specified file type

· path Specifies the file paths to be backed up

So how does Android m implement automatic backup of the app, in fact, he is to get the app read and write access to the app's app manifest to write the relevant backup configuration inside.

three. About Recovery

When data needs to be restored, Backup Manager calls the Requestrestore () method to download the data from Google Drive

Then call the Onstore () method to restore the data to your device. This method needs to pass three parameters

· Data: A backupdatainput that allows you to read to the backup

· Appversioncode: Is the value of the Android:versioncode attribute in your application, which can be used to determine whether the data format of the application data and the cloud backup is compatible.

· NewState: An open, read-write, parcelfiledescriptor that points to a file that holds the status of your final data backup. This object will be returned with the Oldstate variable name the next time the onbackup is called.

When you execute the Onstore () method, the Readnextheader () method is called first to traverse all the entities that exist in the data group. Each entity is found with the following actions:

    1. Get the key of the entity using the Getkey () method

2. Compare the key of the entity to the key value of all static final types declared in the Backupagent class, and once you match one of your existing key values, the data downloaded from the cloud will be extracted and saved to your device.

The Helper.restoreentity () method is used to save the data, and he writes the data to a file that matches the key.

Four. Can we make it?

As mentioned above, Google realizes automatic backup, actually obtains the other app's read and write permission, writes the corresponding configuration in the app to realize the backup. So why does Google have access to other apps ' read and Write permissions? Because he has system privileges, he has read and write access to all the apps installed in his system. But the app and app can't get access to each other's read and write permissions. Android Apps borrow Linux sandbox technology to isolate different apps, and the isolation between apps is primarily resource isolation and access isolation. Although the app privilege mechanism provides the possibility for the exchange of resources between applications, the app can access the services of other programs after the application has been granted permission and authorized by the user. But this requires two apps to be configured in the code. The first thing to do is to sign the same private key to ensure that two apps run in the same process, and then customize the <permission> tag to ask the user if they want to access the app's read and write permissions. But that's not practical, and we can't work with all apps to get them to join in the program code that lets us get their read and write permissions.

Android M new Features-Application Data automatic backup function

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.