0

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?

snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • I guess that update is a case when GCM/FCM token could change. Anyway, 1st thing your app does - asks for current GCM/FCM token using google lib and its up to google lib to return a proper token, regardless was it changed or not. Why do you think that restoring token from SharedPrefs is a good idea in case of update? – Stan Mar 02 '18 at 11:49
  • I don't think it is, so I excluded shared preferences file, like all tutorials suggest, links in question. Problem is that I have also some other prefs stored in same file, which I want to leave/restore (lose only GCM/FCM token). And the question is: can I prevent not-restoring particular declared XML file, when app is already released and I'm making an update? – snachmsm Mar 02 '18 at 13:46
  • Actually you should store only FCM/GCM token (or any other data that should/could be lost) in that file so you gonna loose only the token. There is no way to manage key/value pair of one file, but only the whole file. So I suggest you to make update counting on that - exclude anything else from the SP file with FCM/GCM token OR declare a new SP file for token storing only + add some migration codez ) – Stan Mar 03 '18 at 11:41
  • Do you understand that (in moment of writing that old question) I had already released app with excluded whole SP file, with token AND push settings (opt-in categories), which I wanted to keep? Only them, not token? But I've excluded whole file and re-storing process is applied also during simple update (didn't know that, comes in test when was releasing next version)... Not only reinstalation on new device e.g. when user is transfering account to new device... (then push settings may be lost, they should only then) – snachmsm Mar 03 '18 at 13:33

1 Answers1

0

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.

Community
  • 1
  • 1
Teyam
  • 7,686
  • 3
  • 15
  • 22
  • I have code excluding important sharedpref file inside released app. Now I want to keep/restore this file, because it should not be deleted. It may be deleted only _"during device setup or adb"_ as DOC says, but now I see (testing signed update apk file) my file is excluded/removed also when simple update is installing... (so this backup feature works in wider range as documented... or I don't uderstand what _during device setup_ means...) – snachmsm Dec 28 '16 at 10:19