I do not understand why you ran into this problem.
I have the same problem: I want to support backup using an application that also supports 1.5 (API 3).
There is no problem creating my BackupAgentHelper class, since this class is never called from my own code, but from the BackupManager ie of the system itself. Therefore, I do not need to wrap it, and I do not understand why you should do this:
public class MyBackupAgentHelper extends BackupAgentHelper { @override onCreate() { \\do something usefull }
However, you want to start the backup to do this, you need to call BackupManager.dataChanged() whenever your data changes, and you want to inform the system about its backup (using BackupAgent or BackupAgentHelper ) ..
You need to wrap this class as you call it from your application code.
public class WrapBackupManager { private BackupManager wrappedInstance; static { try { Class.forName("android.app.backup.BackupManager"); } catch (Exception e) { throw new RuntimeException(e); } } public static void checkAvailable() {} public void dataChanged() { wrappedInstance.dataChanged(); } public WrapBackupManager(Context context) { wrappedInstance = new BackupManager(context); } }
Then you call it from your code when you change the preference or save some data. Some code from my application:
private static Boolean backupManagerAvailable = null; private static void postCommitAction() { if (backupManagerAvailable == null) { try { WrapBackupManager.checkAvailable(); backupManagerAvailable = true; } catch (Throwable t) { backupManagerAvailable = false; } } if (backupManagerAvailable == true) { Log.d("Fretter", "Backup Manager available, using it now."); WrapBackupManager wrapBackupManager = new WrapBackupManager( FretterApplication.getApplication()); wrapBackupManager.dataChanged(); } else { Log.d("Fretter", "Backup Manager not available, not using it now."); }
So hopefully this will work for you!
(If you invoke adb shell bmgr run every time you want to emulate the actual system-initiated backup process, it should correctly back up and restore when you reinstall the application.)
Peterdk
source share