jeudi 25 février 2016

Android: Backup SQLite database using BackupAgentHelper not working at all

I have gone through a lot of posts and read the documentation about 10 times. But still I am not able to backup my database using FileBackupHelper. I am using BackupAgentHelper.

Please I need some help!!

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
        package="...">

<application
    android:allowBackup="true"
    android:restoreAnyVersion="true"
    android:backupAgent=".MyBackupAgent"       
    <meta-data android:name="com.google.android.backup.api_key" android:value="..." />
</application>

</manifest>

MyBackupAgent.java

public class MyBackupAgent extends BackupAgentHelper {
    public void onCreate() {
        FileBackupHelper helper = new FileBackupHelper(this, this.getDatabasePath("mydb").getAbsolutePath());
        addHelper("db_file", helper);
        Log.d("Test", "Adding backup agent");  
    }
}

After that I run:

adb shell bmgr run

The logcat output is:

D/Test: Adding backupagent...
V/BackupServiceBinder: doBackup() invoked
D/BackupHelperDispatcher: handling existing helper 'db_file' android.app.backup.FileBackupHelper@425ab2f8

After that, I reinstall the app. But still the database is not restored.

Any help would be highly appreciated.

Aucun commentaire:

Enregistrer un commentaire