3

I'd like to use the BackupManager to back a DB for my app. The documentation talks about BackupAgent and BackupAgentHelper, and it states that you want to use BackupAgent if you have a DB.

On the other hand, the BackupAgentHelper has a neat FileBackupHelper that makes things quite easy.

My questions:

1) Is it possible to use FileBackupHelper to backup the .sqlite file in /data/data/<myapp>/databases?

2) if not, is it possible to use the SQLiteOpenHelper's methods inside onBackup() and onRestore() (onCreate/onUpgrade to backup/restore)?

HitOdessit
  • 7,198
  • 4
  • 36
  • 59
llappall
  • 2,852
  • 3
  • 23
  • 26
  • possible duplicate of [Android backup/restore: how to backup an internal database?](http://stackoverflow.com/questions/5282936/android-backup-restore-how-to-backup-an-internal-database) – Pointer Null Mar 15 '12 at 10:25

1 Answers1

0

It is possible. When you extend BackupAgentHelper and implement its onCreate(), you can do something like this in there:

addHelper(STATS_BACKUP_KEY, new DbBackupHelper(this, "my_db_name"));

And your DbBackupHelper class can look like this:

public class DbBackupHelper extends FileBackupHelper {

    public DbBackupHelper(Context ctx, String dbName) {
        super(ctx, "../databases/" + dbName);
    }
}

For a full example, check out the Andlytics project on GitHub: AndlyticsProject.

IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147