How to backup you preferences to Google

The documentation is not very good on how to use Google as backup for restoring your apps data. Whats missing is actually the naming representation of the file in your code:

- use your package name, underscore, and just "preferences".

This account for a simple preferences setup, where you not have set the file-name yourself.

Here is a working example:

public class MyGoogleBackupSimple extends BackupAgentHelper {

    // The name of the SharedPreferences file
    static final String PREF_ALL = "com.heleneapps.mybeerlist_preferences";

    // A key to uniquely identify the set of backup data
    static final String PREFS_BACKUP_KEY = "whatever";

    public void onCreate() {
        SharedPreferencesBackupHelper helperPrefs = new SharedPreferencesBackupHelper(this,
        addHelper(PREFS_BACKUP_KEY, helperPrefs);

No comments:

Post a Comment