2013-08-02 44 views
0

我有问题,否则我不会在这里。谷歌备份服务不起作用

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

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 

} 

贮藏发生在mainactivity:

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" > 

...

回答

0

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

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