I'm trying to backup my shared preferences file, made a BackupAgentHelper -
public class MyPrefsBackupAgent extends BackupAgentHelper {
// The name of the SharedPreferences file
static final String PREFS = "favorites";
// A key to uniquely identify the set of backup data
static final String PREFS_BACKUP_KEY = "prefs";
// Allocate a helper and add it to the backup agent
@Override
public void onCreate() {
SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, PREFS);
addHelper(PREFS_BACKUP_KEY, helper);
}
on MainActivity -
bm = new BackupManager(getApplicationContext());
public static void requestBackup() {
bm.dataChanged();
}
and when saving the shared preferences calling the requestBackup method -
editor.commit();
MainActivity.requestBackup();
manifest as below-
<application
android:allowBackup="true"
android:backupAgent="MyPrefsBackupAgent">
<meta-data android:name="com.google.android.backup.api_key"
android:value="AEdPqrEAAAAI1Ap52upiK6qBdhShe4Diyzti2CLyayVouApfKQ" />
it is not working, what am I doing wrong?