I am using this code for saving database, using BackupAgent
class
public class MyBackupAgent extends BackupAgentHelper {
String DATABASE_NAME = "mydb";
String DATABASE_FILE_NAME = "mydb.db";
@Override
public void onCreate() {
SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, PREFS);
addHelper(PREFS_BACKUP_KEY, helper);
FileBackupHelper dbs = new FileBackupHelper(this, DATABASE_FILE_NAME);
addHelper("dbs", dbs);
}
@Override
public File getFilesDir() {
File path = getDatabasePath(DATABASE_FILE_NAME);
return path.getParentFile();
}
}
Now after that i want to know how to restore database? Please help me about this, Thanks in advance
In theory only with that code and changes on AndroidManifest the backup should work as per Android Google page inform.
Please take a look on this page: http://developer.android.com/guide/topics/data/backup.html
For summary from this above page:
To implement a backup agent, you must:
1 - Declare your backup agent in your manifest file with the android:backupAgent attribute. 2 - Register your application with a backup service. Google offers Android Backup Service as a backup service for most Android-powered devices, which requires that you register your application in order for it to work. Any other backup services available might also require you to register in order to store your data on their servers. 3 - Define a backup agent by either: Extending BackupAgent or Extending BackupAgentHelper;