Should full backup content xml file be empty or not added at all to include all?

AndroidXmlBackup

Android Problem Overview


So I was adding some stuff to my application manifest and I saw that I had a warning on my application tag:

> On SDK version 23 and up, your app data will be automatically backed up and restored on app install. Consider adding the attribute android:fullBackupContent to specify an @xml resource which configures which files to backup.

And then I searched up for that. Apparently there are only 2 tags for that: <include> and <exclude>. I don't want to exclude any files from the backup as I don't have any local-depending files, and I don't need any <include> tags as

> <include>: Specifies a set of resources to back up, instead of having the system back up all data in your app by default.

When I saw that if I don't put any <include> tags, then the system will back up all data in your app by default, which is exactly what I want.

Now I have this question: should I add the backup_content.xml file, but empty as the default settings are good, or not add the file at all? (in which case Android Studio will complain)

Android Solutions


Solution 1 - Android

Fast Solution:

AndroidManifest.xml

<application
    android:allowBackup="true"
    android:fullBackupContent="true"
    ...
    ...
    ...
</application>

For more details see: https://developer.android.com/guide/topics/data/autobackup

Solution 2 - Android

If you want to silence the warnings, but don't need to exclude any files from the backup, you could also just add tools:ignore="AllowBackup" to the application tag in your AndroidManifest.xml to suppress the warning (or use the Suppress button that you get when viewing the warning details).

Solution 3 - Android

Correct solution:

The warning is because is missing <full-backup-content> resource.

For this we have android:fullBackupContent in the application tag, which points to a XML file that contains full backup rules for Auto Backup. These rules determine what files get backed up.

Example:

<application ...
    android:fullBackupContent="@xml/my_backup_rules">
</application>

Create an XML file called my_backup_rules.xml in the res/xml/ directory. Inside the file, add rules with the <include> and <exclude> elements. The following sample backs up all shared preferences except device.xml:

<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
    <include domain="sharedpref" path="."/>
    <exclude domain="sharedpref" path="device.xml"/>
</full-backup-content>

References for more information:

https://developer.android.com/guide/topics/data/autobackup https://betterprogramming.pub/androids-attribute-android-allowbackup-demystified-114b88087e3b

Solution 4 - Android

I also struggled the same question and couldn't find an answer. So for backup all, I tried making a backup.xml file like that:

<?xml version="1.0" encoding="utf-8"?>
   <full-backup-content>

   </full-backup-content>

and it works fine.

EDIT 06/04/21

Just got an official answer from Google IssueTracker: >The answer to your question appears at the beginning of the section titled Include and exclude files: "By default, the system backs up almost all app data". >In order to back up all supported data, don't include android:fullBackupContent in your manifest file.

Solution 5 - Android

Here are a few tidbits I found here.

> The default behaviour on Marshmallow and later for apps that target 23+ is to back everything up

I read that as reason to Suppress the warning, if wanting this behavior.

> Auto Backup will by default not restore a backup that was created from a newer version of your app, because it assumes it may not work for you. This might be a problem if your user is migrating to a new device that has an older version of your app preinstalled, because it would mean that nothing is restored.

If you are confident you can handle forward compatibility, you can use android:restoreAnyVersion="true" to override the behaviour.

Solution 6 - Android

you can add android:fullBackupContent="true" in your androidmanifest.xml

Solution 7 - Android

<application
        android:allowBackup="true"
        android:fullBackupOnly="true">
</application>

Solution 8 - Android

I think when you don't define any exclude or include it makes a full backup.

> : Specifies a set of resources to back up, instead of having the system back up all data in your app by default. If you specify an element, the system backs up only the resources specified with this element. You can specify multiple sets of resources to back up by using multiple elements

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChaozView Question on Stackoverflow
Solution 1 - Androiduser_MGUView Answer on Stackoverflow
Solution 2 - AndroidHemaolleView Answer on Stackoverflow
Solution 3 - AndroidHenrique MonteView Answer on Stackoverflow
Solution 4 - AndroidAvitalView Answer on Stackoverflow
Solution 5 - AndroidseekingStillnessView Answer on Stackoverflow
Solution 6 - AndroidbehradView Answer on Stackoverflow
Solution 7 - AndroidZombieSlayerView Answer on Stackoverflow
Solution 8 - AndroidLaireView Answer on Stackoverflow