title: Android Saving Shared Preferences using Backup Agent
body: <p>In my backupagent class I have this:</p>
  
  <pre><code>import android.app.backup.BackupAgentHelper;
  import android.app.backup.SharedPreferencesBackupHelper;
  
  public class TheBackupAgent extends BackupAgentHelper {
      // The names of the SharedPreferences groups that the application maintains.  These
      // are the same strings that are passed to getSharedPreferences(String, int).
      static final String RECIPE_NAMES = "MyRecipeNames";
      static final String TEST = "testSave";
  
      // An arbitrary string used within the BackupAgentHelper implementation to
      // identify the SharedPreferencesBackupHelper's data.
      static final String MY_PREFS_BACKUP_KEY = "myprefs";
  
      // Simply allocate a helper and install it
      public void onCreate() {
          SharedPreferencesBackupHelper helper =
                  new SharedPreferencesBackupHelper(this, TEST);
          addHelper(MY_PREFS_BACKUP_KEY, helper);
      }
  }
  </code></pre>
  
  <p>I then have code to store a string into the testSave Shared Preferences and request a backup of the preferences:</p>
  
  <pre><code>public void requestBackup() {
      BackupManager bm = new BackupManager(this);
      bm.dataChanged();
  }
  
  public void saveRecipe (View v) {
  
      SharedPreferences prefs = getApplicationContext().getSharedPreferences("testSave", 0);
      SharedPreferences.Editor editor = prefs.edit();
      editor.putString("testString", "This is my saved data.");
      editor.apply();
  
      requestBackup();
  }
  </code></pre>
  
  <p>I then try to uninstall and reinstall the app and the saved data is gone. I have added the required code to the Manifest but it is not working. Does my app need to be on the play store? I really have no idea why it won't work.</p>