Google备份服务不起作用

时间:2013-08-02 12:10:32

标签: android backup

我有问题,否则我不会在这里。

我正在制作备份服务,但到目前为止,它根本不起作用。不知道它有什么问题,但在测试时(通过模拟器或电话,解释方式),数据将无法恢复。也许有人可以提供帮助?

MyAppsBackupAgent

public class AppsBackupAgent extends BackupAgentHelper {

// The name of the SharedPreferences file
static final String PREFS = "uidpref";

// A key to uniquely identify the set of backup data
static final String PREFS_BACKUP_KEY = "uidpref";

// 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);
}

@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
        ParcelFileDescriptor newState) throws IOException {
    // TODO Auto-generated method stub

}

@Override
public void onRestore(BackupDataInput data, int appVersionCode,
        ParcelFileDescriptor newState) throws IOException {
    // TODO Auto-generated method stub

}

存储发生在主要活动中:

SharedPreferences UIDpref = getSharedPreferences("uidpref", 0);
    Log.e("CODE", preferences.getBoolean("IDgenerated", false)+""); 
    BackupManager mBackupManager = new BackupManager(getApplicationContext());

    if(!preferences.getBoolean("IDgenerated", false)){
        SharedPreferences.Editor UIDedit = UIDpref.edit();
        String rnd = GenerateUID(30);
        UIDedit.putString("UID", rnd);
        UIDedit.putBoolean("IDgenerated", true);
        UIDedit.commit();
        mBackupManager.dataChanged();
    }

并表明:

<application
    android:backupAgent="ee.elven.katja.AppsBackupAgent"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"  >

...

1 个答案:

答案 0 :(得分:0)

这是一个老问题,但也许你还需要一个答案。在您的AppsBackupAgent实施中,删除onRestore()onBackup()方法。

继承BackupAgentHelper实现使用调度程序将恢复/备份事件传递给已注册的帮助程序。您的实施只会禁用此工作。