Restoring some XML fields from excluded SharedPreference file (using fullBackupContent)

508 views Asked by At

I have an app with Google Cloud Messaging feature and also optional fullBackupContent declared like this:

<application
    android:fullBackupContent="@xml/backup_rules">

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

push.xml contains GCM registration ID, which should be excluded from backuping like above (some info HERE and HERE). But not only this one field is in preferences xml... it contains also some "internal" settings like custom push categories enabled/disabled or flag firstRunShowDialogAboutPushMessages (default is true, dismissing dialog is setting flag to false).

And everything works good, too good... Above code is currently in Google Play and now I'm planning to release update. During tests I've noticed that this backup feature is performed also in case of update... Can anybody confirm that it should? Apps target: API24, testing device: current API25. Doc says:

Data is restored whenever the app is installed, either from the Play store, during device setup (when the system installs previously installed apps), or from running adb install. The restore operation occurs after the APK is installed, but before the app is available to be launched by the user.

So during device setup or adb... Is it means update through Google Play or signed file on GP version installation also? Without any account/device restoring, just an update? As far as I see... Now when I release new version (even without excluded push.xml) this file will be NOT backuped, because current has exlusion... and update will "reset" push settings in app (enabling all options/categories and firstRunShowDialogAboutPushMessages=true, as default, even when user opted-out).

So what can I do now? I may move GCM registration ID to separated SharedPreference xml file and exclude only this one, but with next update all GCM settings will be lost anyway, so bad... Any idea, any help in this case?

1

There are 1 answers

1
Teyam On

I'm not sure what kind of confirmation were you asking for but IMHO, the documentation is already a good source of confirmation.

So what can I do now?

You may want to also check suggested solution in this SO post and visit Testing Backup and Restore for helpful insights.