Auto backup in android-don’t do it unless you know it

Auto backup is a property in application tag in the android manifest file which we hardly care about. Recently me and my team started observing some strange behaviours in our application which we technically didn’t code.

First, let me tell you what was the issue. We observed that even after uninstalling the application from the device and removing the application folder, on reinstall we found the app on the same state as before uninstall, on some research we found it happened due to auto backup feature added in android 6 which automatically uploads user’s data to google drive with amount limited to 25MB per app. You may think it’s good well it is if you have coded your app to handle that otherwise, you’ll observe unexpected issues with your app. Also, the android system asks user’s permission to backup device data.

Options we had-either disable it completely by setting android:allowBackup=“false” in manifest and also same in the manifest of native or other modules you have in your app or add a backup rules file to customise what you want to backup.

Files which are backed up:

1- Shared preference.

2- directory returned by getFilesDir().

3-getDataBase(path) also includes files created by SQLiteOpenHelper.

4- files in directories created with getDir(Sring, int).

5- files on external storage returned by getExternalFilesDir (String type).

We can customise what to be backed up by creating a backup rules file in xml and add it’s reference in manifest using

android:fullBackupContent=”@xml/my_backup_rules”

In this file, we can specify what to be added and removed

<full-backup-content>
<include domain=["file" | "database" | "sharedpref" | "external" | "root"]
path="string" />
<exclude domain=["file" | "database" | "sharedpref" | "external" | "root"]
path="string" />
</full-backup-content>

domain- specifies location of resource and path specifies file or folder to be included and excluded.

for ex : <exclude domain=”database” path=”AppDatabase.db” />
<include domain=”sharedpref” path=”Prefs.xml” />

AppDatabase.db is name of my database and Prefs.xml name of my preference.

For detailed queries check out this link. Happy coding.

Also let’s connect on facebook, twitter, github and linkedin.