Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't see why you run into this problem.</p> <p>I have the same issue: I want to support backup with a app that supports also 1.5 (API 3).</p> <p>There is no problem in creating my <code>BackupAgentHelper</code> class, since that class is never called from my own code, but from the <code>BackupManager</code> i.e. the system itself. Therefore I don't need to wrap it, and I don't see why you should be doing that:</p> <pre><code> public class MyBackupAgentHelper extends BackupAgentHelper { @override onCreate() { \\do something usefull } </code></pre> <p>However, you do want to get a backup running, to do that you need to call on <code>BackupManager.dataChanged()</code> whenever your data changes and you want to inform the system to backup it (using your <code>BackupAgent</code> or <code>BackupAgentHelper</code>).</p> <p>You do need to wrap that class, since you call it from you application code.</p> <pre><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); } } </code></pre> <p>You then call it from your code when you change a preference or save some data. Some code from my app:</p> <pre><code> 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."); } </code></pre> <p>So, hopefully this works for you! </p> <p>(If you call <code>adb shell bmgr run</code> every time you want to emulate the actual system initiated backupprocess it should properly backup and restore when you reinstall the app.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload