Skip to content

Instantly share code, notes, and snippets.

@ccjeng
Created June 22, 2016 04:39
Show Gist options
  • Save ccjeng/9436eebcc74f3c9b3bebc9ff027c008f to your computer and use it in GitHub Desktop.
Save ccjeng/9436eebcc74f3c9b3bebc9ff027c008f to your computer and use it in GitHub Desktop.
BackupAgent for Android Backup API
public class TheBackupAgent extends BackupAgentHelper {
private static final String DB_NAME = "test.db"; // db name
@Override
public void onCreate() {
FileBackupHelper dbs = new FileBackupHelper(this, DB_NAME);
addHelper("dbs", dbs);
}
@Override
public File getFilesDir() {
final File f = getDatabasePath(DB_NAME);
return f.getParentFile();
}
}
public class TheBackupAgent extends BackupAgentHelper {
static final String PREFS_DISPLAY = "displayprefs";
static final String PREFS_SCORES = "highscores";
static final String MY_PREFS_BACKUP_KEY = "myprefs";
void onCreate() {
SharedPreferencesBackupHelper helper =
new SharedPreferencesBackupHelper(this, PREFS_DISPLAY, PREFS_SCORES);
addHelper(MY_PREFS_BACKUP_KEY, helper);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment