0

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?

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for the reply. How do you incorporate the "adb" command in an application? I have a SQLLite database that needs to be backed and restored for application installation. It may be a bad idea to use the Backup service. I implemented a file backup using JSONObject object in the application folder that works now. Has anyone tried Google drive as a backup device? In that case, the backup file may be used by a different device. I have an application that uses Web service for data store and backup. In this application, I do not want to use a central server to do backup/restore.
adb is a desktop application and cannot be run from within an app
Is there a way to log on the Google cloud to see the backup file?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.