我有问题,否则我不会在这里。
我正在做备份服务,但到目前为止,它根本不起作用。不知道这是什么问题,但是在测试时(通过模拟器或通过电话,解释方式),数据将无法恢复。也许有人可以帮忙?
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" >
...