BackupAgentHelper causing data loss

95 views Asked by At

I currently have BackupAgentHelper implemented to backup SharedPreferences. However, occasionally when I release an update I get messages from users saying that the update caused the data in their SharedPreferences to be wiped completely. After investigation the only thing that could be causing it is the BackupAgentHelper, although the implementation is rather standard so I'm not completely sure why that is.

public class CloudBackup extends BackupAgentHelper {

 static final String MY_PREFS_BACKUP_KEY = "ACNLPrefs";

 @Override
 public void onCreate() {

     SharedPreferencesBackupHelper helper =
             new SharedPreferencesBackupHelper(this, "ACNLCaught",
                     "ACNLVersion",
                     "ACNLSort");
     addHelper(MY_PREFS_BACKUP_KEY, helper);
 }

}

Since it occurs immediately after an update (this isn't 1 particular update either, it seems to happen to a very small number of users after each update), I can only assume it's related to when the SharedPreferences are being restored. If a user installed the app, generated a lot of data and then received the update very shortly afterwards, I guess it is possible that the update will have been downloaded before the BackupAgent had had the opportunity to make the backup.

Any suggestions would be most helpful - I'd rather not have any users lose all of their data.

1

There are 1 answers

0
ctate On

You don't get any restore activity when your app is updated in place. The only time you will see a restore happen in normal use is when your app is installed from a clean state (either the first-ever install on that device, or after the user has done a full uninstall of the app and then later reinstalled it).

Some Android device vendors have made changes to the way SharedPreferences are handled; I wonder whether the affected users have run into some rare bug related to that.