Skip to content Skip to sidebar Skip to footer

Android SharedPreferences Backup Not Working

I've been doing my homework on how to backup SharedPreferences in my Android application, especially using reflection to maintain backwards compatibility. At least I've been trying

Solution 1:

In your main calling activity (first one that starts in your app), you need to instantiate BackupManager:

BackupManager mBackupManager = new BackupManager(getApplicationContext());

This will tell the backupmanager to look for the backup file and load it.

You need to make sure the preferences file is format "packagename_preferences" eg. andy_preferences. And use the same name when you first saved your preferences. (Very important!)

After the your settings activity saves via apply() or commit(), you need to tell BackupManager that something has changed so include immediately after:

mBackupManger.dataChanged();

Post a Comment for "Android SharedPreferences Backup Not Working"