BackupManager 不调用 onBackup

BackupManager don't call onBackup

我有一个资产数据库。我想备份和恢复我的数据库。 BakupAgent:

public class MBackupAgent extends BackupAgentHelper {

public static final String PREFS = "data_prefs";
public static final String PREFS_BACKUP_KEY = "myprefs";
// Allocate a helper and add it to the backup agent
@Override
public void onCreate() {
     SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, PREFS);
        addHelper(PREFS_BACKUP_KEY, helper);

    FileBackupHelper hosts = new FileBackupHelper(this,
            "../databases/" + DBHelper.DB_NAME);
        addHelper(DBHelper.DB_NAME, hosts);
}

@Override 
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, 
            ParcelFileDescriptor newState) throws IOException { 

    Log.d("ConnectBot.BackupAgent", "onBackup called"); 
 synchronized (DBHelper.dbLock) { 
     Log.d("ConnectBot.BackupAgent", "onBackup called"); 
  super.onBackup(oldState, data, newState); 
 } 
} 

@Override 
public void onRestore(BackupDataInput data, int appVersionCode, 
  ParcelFileDescriptor newState) throws IOException { 
 Log.d("ConnectBot.BackupAgent", "onRestore called"); 

 synchronized (DBHelper.dbLock) { 
  Log.d("ConnectBot.BackupAgent", "onRestore in-lock"); 

  super.onRestore(data, appVersionCode, newState); 
 } 
} 

调用 onRestore 工作正常。但是 onBackup 没有。我只能通过 adb shell 进行备份。我在 SQLiteOpenHelper 中这样调用 dataChanged:

public void setUserName(String name){
    synchronized (dbLock) {
     SQLiteDatabase db = this.getWritableDatabase(); 
       ContentValues values = new ContentValues(); 
       values.put(KEY_NAME, name);
       db.update(TABLE_NAME, values,"oid="+1,null);
       db.close();
    }
    BackupManager.dataChanged("my package name");

}

我没被拍到什么?

试试看这个:http://developer.android.com/tools/help/bmgr.html 默认情况下,无法保证何时调用 onBackup。使用 "adb shell bmgr run".

立即触发备份