initial use of sharedpreferences.
BackupManager bm = new BackupManager(getApplicationContext());
SharedPreferences sharedPreferences = getSharedPreferences("AppData", MODE_PRIVATE);
if(sharedPreferences.getBoolean("my_first_time", true)) {
sharedPreferences.edit().putBoolean("my_first_time", false).apply();
sharedPreferences.edit().putString("user_id", String.valueOf(dbh.insertUserId())).apply();
sharedPreferences.edit().putInt("noteIndex", -1).apply();
sharedPreferences.edit().putInt("checklistIndex", -1).apply();
bm.dataChanged();
}
Backing up data
public class MyPrfsBackupAgent extends BackupAgentHelper {
@Override
public void onCreate() {
SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, "AppData");
addHelper("sharedprefs_key", helper);
}
}
My goal is to backup the whole sharedpreferences file 'AppData' and restore it after re-installation of the feature is failing to complete its task. Ive tried it with allowbackup in manifest on both true and false, and running it on my actual device to test it but nothing seems to work accordingly.
items added to AndroidManifest.xml in attempt to fix this
android:backupAgent=".BackupData$MyPrfsBackupAgent"
<meta-data android:name="com.google.android.backup.api_key"
android:value="value" />
I followed the docs on this as well as other stackoverflow references but none have helped me solve the problem. I would be open to trying a different way of backup/restoring but cant find another and wont use autoBackup because it targets sdk 23 while my min is 21.