I have done the following to get SQLite database Backup/Restore working.

(1)get registration from Google.

[http://developer.android.com/google/backup/signup.html][1]

(2)Add the key to Manifest xml file

<application> <meta-data android:name="com.google.android.backup.api_key" android:value="backup_service_key_from_google" /> ... </application>

(3)Add my backagent agent in the XML file

<application
    android:allowBackup="true"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" 
     ...
    android:backupAgent="MyBackupAgent" android:restoreAnyVersion="true"
    >

(4)Create a class called MyBackupAgent

    class MyBackupAgent extends BackupAgentHelper{
   @Override
   public void onCreate(){
      FileBackupHelper dbs = new FileBackupHelper(this, "../databases/"+SQLHelp.dbName);
      addHelper(SQLHelp.dbName, dbs);
   }
}

(5)Call the backup Manager for backup

BackupManager  mBackupManager = new BackupManager(this);
    mBackupManager.dataChanged();

After step 5, I do not see anything happening. I put a break point in MyBackupAgent. Nothing stops in the onCreate() function.

Any suggestions?

有帮助吗?

解决方案

It could be that you simply have not waited long enough. From the docs in reference to the call to dataChanged:

This call notifies the backup manager that there is data ready to be backed up to the cloud. At some point in the future, the backup manager then calls your backup agent's onBackup() method.

The backup is not initiated right away. It is scheduled for a future time. You can initiate a backup right away by using adb on the command line.

See http://developer.android.com/guide/topics/data/backup.html (Testing your backup agent)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top